我在jQuery中使用通常的链接延迟方法进行一系列连续的AJAX调用。第一次调用返回一个值列表,随后的调用是使用返回的列表条目进行的。在第一次调用返回列表后,随后的调用可以按任意顺序完成,但必须一次完成一次。所以这是我使用的:继续失败的jQuery推迟链
$.when(callWebService()).then(
function (data) {
var looper = $.Deferred().resolve(),
myList = JSON.parse(data);
for (var i in myList) {
(function (i) {
looper = looper.then(function() { // Success
return callWebService();
},
function (jqXHR, textStatus, errorThrown) { // Failure
if (checkIfContinuable(errorThrown) == true)
continueChain();
else
failWithTerribleError();
});
})(i);
}
});
事实证明,后来的调用可能会失败,但我仍然想要做其余的调用。在我的上市,这就是创造性的伪代码这一点是为了做:
if (checkIfContinuable(errorThrown) == true)
continueChain();
else
failWithTerribleError();
如何在地球上我虽然实现continueChain?看起来,任何延期的失败都会导致链条的其他部分也失败。相反,我想记录错误并继续处理列表的其余部分。
'continueChain'和'failWithTerribleError'做了什么? – Joseph
请参阅http://stackoverflow.com/questions/27171161/handling-different-success-and-fail-states-for-multiple-ajax-call-using-deferred,http://stackoverflow.com/questions/28131082/ jquery-ajax-prevent-fail-in-a-deferred-sequential-loop – guest271314
@CobusKruger尝试使用'.always()' – guest271314