response
response(status, body, headers, statusText)
Used to detail a response.
Example:
fixture({url: "/todos/{action}"},
function(request, response, headers, ajaxSettings){
response(
401,
{ message: "Unauthorized"},
{ "WWW-Authenticate": 'Basic realm="myRealm"'},
"unauthorized");
}
});
$.post("/todos/delete");
You don't have to provide every argument to response
. It can be called like:
// Just body
response({ message: "Hello World"});
// status and body
response(401, { message: "Unauthorized"});
// body and headers
response('{"message":"Unauthorized"}',{"WWW-Authenticate":'Basic realm="myRealm"'});
// status, body statusText
response(401, '{"message":"Unauthorized"}','unauthorized');
The default statusText
will be ok
for 200 <= status < 300, status === 304
and error
for everything else.
Parameters
- status
{Number}
:The HTTP response code. Ex:
200
. - body
{Object}
:A JS object that will be serialized and set as the responseText of the XHR object, or the raw string text that will be set as the responseText of the XHR object.
- headers
{Object}
:An object of HTTP response headers and values.
- statusText
{String}
:The status text of the response. Ex:
"ok"
for 200.