requestHandler
Defines the XHR response for a given trapped request.
requestHandler(request, response(...), requestHeaders, ajaxSettings)
Defines the XHR response for a given trapped request.
import {fixture, ajax} from "can";
fixture( { method: "get", url: "/todos" },
( request, response, headers, ajaxSettings ) => {
console.log( request.method ); //-> "get"
console.log( request.url ); //-> "/todos"
console.log( request.data ); //-> {complete: "true"}
}
);
ajax( {url: "/todos?complete=true"} );
Templated url
data will be added to the requestHandler
's request
argument's data
property:
import {fixture, ajax} from "can";
fixture( { url: "/todos/{action}" },
( request, response, headers, ajaxSettings ) => {
console.log( request.method ); //-> "post"
console.log( request.url ); //-> "/todos/delete"
console.log( request.data ); //-> {action: "delete"}
}
);
ajax( {type: "POST", url:"/todos/delete"} );
Parameters
- request
{request}
:Information about the request. The request's data property will contain data from the request's querystring or request body. Also any templated values in the ajaxSettings's
url
will be added. - response
{response()}
:A callback function that provides response information.
- requestHeaders
{Object}
:Headers used to make the request.
- ajaxSettings
{Object}
:The settings object used to match this request.