根据这篇文章: https://stackoverflow.com/a/17548609/985704
使用jQuery.when执行多个同时的ajax请求。
var requests = Array();
requests.push($.get('responsePage.php?data=foo'));
requests.push($.get('responsePage.php?data=bar'));
var defer = $.when.apply($, requests);
defer.done(function(){
// This is executed only after every ajax request has been completed
$.each(arguments, function(index, responseData){
// "responseData" will contain an array of response information for each specific request
});
});
当所有请求都完成后,我能确定($ .each)的参数与请求的顺序相同吗?这是在某处记录的吗?
答案 0 :(得分:1)
Per JasonP :(谢谢)
是。 “传递给doneCallbacks的参数为每个Deferred提供了已解析的值,并匹配Deferreds传递给jQuery.when()的顺序。” api.jquery.com/jQuery.when -