我有这个片段。我想准备一个AJAX调用数组,然后调用它们。在所有AJAX完成之后,会发生一些事情,例如: UI渲染。我试过但是在AJAX调用之前调用 then()方法。如何解决?
// In a loop I do this.
var deferred = getDeleteResultDeferred(resultId, deleteResultSuccessHandler);
deferreds.push(deferred);
...
function getDeleteResultDeferred(resultId, deleteResultSuccessHandler) {
var url = getURI("deleteResult");
var deferred = $.ajax({
type : "post",
url : url,
data : "resultId=" + resultId,
success: function(response){
deleteResultSuccessHandler();
}
});
return deferred;
}
// Then I call the AJAXs.
$.when(deferreds).then(function(){
// UI rendering.
});