在多个Ajax请求上时,我可以依赖jQuery。响应的顺序吗? [英] Can I rely on the order of responses from jQuery.when on multiple Ajax requests
本文介绍了在多个Ajax请求上时,我可以依赖jQuery。响应的顺序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此帖子:
https://stackoverflow.com/a/17548609/985704
在执行多个同时ajax请求时使用jQuery。
var个请求= Array();
requests.push($。get(’responsePage.php?data = foo’));
requests.push($。get(’responsePage.php?data = bar’));
var defer = $ .when.apply($,个请求);
defer.done(function(){
//仅在每个ajax请求完成后才执行
$ .each(arguments,function(index ,responseData){
// responseData将包含每个特定请求的响应信息数组
});
});
完成所有请求后,我可以确定($ .each)的参数是按照与请求相同的顺序?
解决方案
Per JasonP :(谢谢)
<是的。 传递给doneCallbacks的参数为每个Deferred提供了解析的值,并与Deferreds传递给jQuery.when()的顺序匹配。 api.jquery.com/jQuery.when –
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?
解决方案
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 –
这篇关于在多个Ajax请求上时,我可以依赖jQuery。响应的顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文