According to the official JQuery documentation:
jqXHR.always(function(data|jqXHR, textStatus, jqXHR|errorThrown) { });An alternative construct to the complete callback option, the .always() method replaces the deprecated .complete()method.
In response to a successful request, the function's arguments are the same as those of .done(): data, textStatus, and the jqXHR object. For failed requests the arguments are the same as those of .fail(): the jqXHR object, textStatus, and errorThrown. Refer to deferred.always() for implementation details.
And let's say that I have the following ajax script :
$.ajax({ url: 'myPHPScript.php', type: 'POST', data: { param_1: 'value_1', param_n: 'value_n'… }, username: 'myLogin', password: 'myPassword', beforeSend: function() { alert('The object was created but not yet initilized'); } }).done(function(data, textStatus, jqXHR) { alert('All the request was sent and we received data'); }).fail(function(jqXHR, textStatus, errorThrown) { alert('Error: the following error was occurred: ' + textStatus + ' Status : ' + jqXHR.Status); }).always(function() { // Here is my problem }); In the .always() function, how can I specify a different function for each statement, I mean when the Deferred is resolved, the always() function gets passed the following params (data, textStatus, jqXHR) however if the deferred is rejected it gets passed (jqXHR, textStatus, errorThrown).
Thanks
.done()and.fail()are for, you can have multiple such callbacks.jqXHRthen?