问题
Per this post: https://stackoverflow.com/a/17548609/985704
Using jQuery.when to perform multiple simultaneous ajax requests.
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
});
});
When all requests are done, can I be sure that the arguments (of the $.each) are in the same order as the requests? Is this documented somewhere?
回答1:
Per JasonP: (thank you)
Yes. "The arguments passed to the doneCallbacks provide the resolved values for each of the Deferreds, and matches the order the Deferreds were passed to jQuery.when()." api.jquery.com/jQuery.when –
来源:https://stackoverflow.com/questions/26239821/can-i-rely-on-the-order-of-responses-from-jquery-when-on-multiple-ajax-requests