What are the parameters sent to .fail in jQuery?

JqueryAjax

Jquery Problem Overview


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) {

Jquery Solutions


Solution 1 - Jquery

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.

Solution 2 - Jquery

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPhillip SennView Question on Stackoverflow
Solution 1 - JquerynathanjosiahView Answer on Stackoverflow
Solution 2 - JqueryOlivier de RivoyreView Answer on Stackoverflow