124

I can’t find the documentation on what the names of the three parameters are when $.ajax fails.

Right now, I’m just using:

.fail(function(A, B, C) {
1
  • 2
    Likely the same that are passed to the error callback: jqXHR, textStatus, errorThrown. Commented Mar 23, 2012 at 22:27

2 Answers 2

110

According to http://api.jquery.com/jQuery.ajax/ the fail callback should be getting:

jqXHR, textStatus, errorThrown

same as error, but error is deprecated:

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

6
  • Ooh, I didn't notice. Thanks for sharing that piece of the documentation. I'm glad jQuery XHR callbacks are finally matching up with Deferreds. Commented Mar 23, 2012 at 22:35
  • 3
    Oh, but the ajaxError method has event, jqXHR, ajaxSettings, thrownError. Commented Mar 23, 2012 at 22:55
  • 6
    Where does it state that the fail callback gets these 3 arguments? It also states so for the complete setting parameter. These are different, e.g. the arguments to complete are different than the arguments passed to done.
    – Tom
    Commented Jan 3, 2013 at 13:23
  • 5
    @Tom, I know I'm way late to respond to you but it is stated here: api.jquery.com/jQuery.ajax/#jqXHR (jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});) Commented Feb 14, 2014 at 5:47
  • 1
    Thanks the jQuery documentation seems to be missing this!
    – Shanimal
    Commented Feb 25, 2016 at 21:39
36

Here an example after looking for the same problem:

this.GetOrderList = function (customerId) {
    var self = this;
    $.post('MySuperServer.aspx', { customerId: customerId })
    .done(function (dataStr) {
        var orderList = jQuery.parseJSON(dataStr);
        self.process(orderList);
    })
    .fail(function (jqXHR, textStatus, error) {
        console.log("Post error: " + error);
    });
}

While debugging, I've got:

  • jqXHR is a JS object
  • textStatus is "error"
  • error is "Internal Server Error", it's the error message sent by the server.
1
  • 1
    Yeah, I think what they're trying to connote by using the word textStatus is that this is the status variable and that it's in text format. As compared to jqXHR, which is a jQuery object. Commented Mar 16, 2015 at 17:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.