how to specify a different function for each statement in JQuery .always() function
根据官方JQuery文档:
1 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.
让我们说我有以下ajax脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $.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 }); |
在.always()函数中,如何为每个语句指定不同的函数,我的意思是当Deferred被解析时,always()函数会传递以下参数(data,textStatus,jqXHR)但是如果延迟被拒绝 它被传递(jqXHR,textStatus,errorThrown)。
谢谢
唯一的好解决方案是不使用
除此之外,您可以检查