I'm working with the jQuery Form Plugin. I have my servers send 200 responses on success, which trips the success
listener perfectly fine. Per the standard, 301 and 302 and transparently redirected by the browser. However, when the server returns, say a 401, the Form Plugin just silently dies. How can I apply a listener to non-200 responses?
views:
12answers:
1
+1
A:
The XHR will have the responseStatus in it - you can use the complete handler instead of 'success' and check that property of the xhr.
$.ajax({ // ...
complete: function(xhr){
if( xhr.responseStatus == 401 ) {
alert( 'awww crap' );
}
}
});
Dan Heberden
2010-07-07 00:45:51
This seems to have worked formidably. I included `success: callback` with `complete: callback`. The complete even handler takes two arguments, the first being an XHR object (status available on `xhr.status`), the second being a string `"error"` or `"success"`.
Steven Xu
2010-07-07 00:49:32
If you need to, you can append to the global ajax events too; the details will be in how you're building your application.
Dan Heberden
2010-07-07 00:54:37