`xhr`, `status` and `ex` variables in a jQuery AJAX request
I am using jQuery 1.6 and I would like to know and understand how I can access response xhr
, status
and ex
variables in the following code:
$jQuery.ajax({
type: "POST",
url: "<some_url>",
error: function(xhr, status, ex) {
var msg = "";
if (xhr) {
msg = "readyState is " + xhr.readyState + ". ";
}
if (ex) {
msg += ex.name + ' - ' + ex.message;
}
alert("ERROR " + msg); }
success: function(jqXHR, status, ex) {
...
}
});
How can I know the full list of all them "acce开发者_JS百科ssible" values like, for example, readyState
for the xhr
(xhr.readyState
), name
and message
for the ex
(ex.name
and ex.message
)?
Moreover, what xhr
and ex
variables represent (I think status
refers to the HTTP status code)?
I strongly suggest you to have a look at the docs.
Here an example.
error(jqXHR, textStatus, errorThrown)Function
A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: Prior to jQuery 1.5, this handler was not called for cross-domain script and JSONP requests. This is an Ajax Event
jQuery has a very good documentation. The docs should be the first place to look at, for questions like yours. If you encounter problems while implementing jQuery you are welcome to ask at SO.
精彩评论