同步3 Ajax请求 [英] Synchronize three ajax requests
本文介绍了同步3 Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个AJAX请求开火了一个又一个,我想能够同时回显所有数据。
I have three AJAX requests firing one after another, and I'd like to be able to echo back all the data simultaneously.
$.ajax ({
type: "POST",
url: "page1.php",
data: "var1=" + var1,
success: function(msg) {
$("#results2").load("page2.php",
function (responseText, textStatus, XMLHttpRequest) {
$("#results3").load("page3.php",
function (responseText, textStatus, XMLHttpRequest) {
if (textStatus == "success") {
$("#results1").html(msg);
}
});
});
}
});
#结果1
,#结果2
和#结果3
都需要下载其相对的数据在同一时间。上述code没有这样做。
#results1
, #results2
and #results3
all need to be loaded with their relative data at the same time. The above code isn't doing it.
推荐答案
您可以使用推迟对象 jQuery的加入1.5版本:
you can use deferred object of jQuery added in 1.5 version:
$.when( $.ajax({1}) , $.ajax({2}) , $.ajax({3}) )
.then(function() {
alert("tada");
});
这篇关于同步3 Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文