我想即时生成 ajax 请求,但我想确保在它们全部完成后得到回调,所以我想将它们包装在 .when .done 语句中,如下所示:
$.when(function(){
$.each(oOptions, function(){
var filePath = this.filePath,
dataType = this.dataType;
$.ajax({
url : filePath,
dataType : dataType
});
});
})
.done(function(){
console.log('success');
console.log(arguments);
})
.fail(function(){
console.log('failed');
});
我的选项是一个对象数组,其中包含我想同时发出的每个 ajax 请求的文件路径和数据类型。此代码将返回成功,但参数只是一个函数,ajax 请求永远不会通过。关于如何做到这一点的任何想法?