我可以依靠的答复从jQuery.when多个Ajax请求的顺序(Can I rely on the

2019-10-21 03:04发布

每这篇文章: 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
    });

});

当所有的请求都做了,我可以肯定的是(的$。每)参数是按顺序相同的请求? 这是记录在案的地方?

Answer 1:

每JasonP:(谢谢)

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



文章来源: Can I rely on the order of responses from jQuery.when on multiple Ajax requests