Can I rely on the order of responses from jQuery.when on multiple Ajax requests

a 夏天 提交于 2019-12-13 18:28:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!