Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the parameters sent to .fail in jQuery?

Tags:

jquery

ajax

People also ask

How get data from Ajax call in jQuery?

ajax({ type: "POST", url: 'test. php', data: {"type":"check"}, success: function(response){ alert(response); } }); There can obviously be more key-val pairs in data. In this case your alert should read: "The type you posted is check".

What is Ajax call in jQuery?

jQuery ajax() Method The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.

How can Ajax call error be resolved?

The best way to bubble that error from the server side (using php) to the client side is to send a header through the Ajax request somewhere in the 400's (which is always associated with errors). Once the Ajax request receives this it will trigger your error function.

How does Ajax return an API call?

The A in Ajax stands for asynchronous. That means sending the request (or rather receiving the response) is taken out of the normal execution flow. In your example, $. ajax returns immediately and the next statement, return result; , is executed before the function you passed as success callback was even called.


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.


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.