【问题标题】:Can I rely on the order of responses from jQuery.when on multiple Ajax requests我可以依赖 jQuery.when 在多个 Ajax 请求上的响应顺序吗
【发布时间】:2014-12-02 02:31:35
【问题描述】:

根据这篇文章: 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 的)参数与请求的顺序相同?这是否记录在某处?

【问题讨论】:

  • 是的。 "传递给 doneCallbacks 的参数为每个 Deferred 提供解析值,并匹配 Deferred 传递给 jQuery.when() 的顺序。" api.jquery.com/jQuery.when

标签: jquery ajax .when


【解决方案1】:

每个 JasonP:(谢谢)

是的。 “传递给 doneCallbacks 的参数为每个 Deferreds 提供解析值,并匹配 Deferreds 传递给 jQuery.when() 的顺序。” api.jquery.com/jQuery.when -

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多