我有两个同时运行的AJAX请求有问题.我有一个PHP脚本,它将数据导出到XSLX.此操作需要花费大量时间,因此我正在尝试向用户显示进度.我正在使用AJAX和数据库方法.实际上,我很确定它曾经工作但我无法弄清楚为什么,它不再适用于任何浏览器.新浏览器有什么变化吗?
$(document).ready(function() {
$("#progressbar").progressbar();
$.ajax({
type: "POST",
url: "{$BASE_URL}/export/project/ajaxExport",
data: "type={$type}&progressUid={$progressUid}" // unique ID I'm using to track progress from database
}).done(function(data) {
$("#progressbar-box").hide();
clearInterval(progressInterval);
});
progressInterval = setInterval(function() {
$.ajax({
type: "POST",
url: "{$BASE_URL}/ajax/progressShow",
data: "statusId={$progressUid}" // the same uinque ID
}).done(function(data) {
data = jQuery.parseJSON(data);
$("#progressbar").progressbar({ value: parseInt(data.progress) });
if (data.title) { $("#progressbar-title").text(data.title); }
});
}, 500);
});
Run Code Online (Sandbox Code Playgroud)
那么,为什么第二个AJAX调用等待第一个完成呢?
我试图使用jQuery并行制作两个ajax请求,如下所示:
var sources = ["source1", "source2"];
$(sources).each(function() {
var source = this;
$.ajax({
async: true,
type: "POST",
data: {post: "data", in: "here"},
url: "/my/url/" + source,
success: function(data) {
process_result(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
我从这个问题得到了基本结构,但我的要求仍然不是并行的."source1"需要一段时间才能完成,我可以在服务器上看到第二个请求在第一个请求完成之前没有进行.
据我所知,我没有任何其他活动请求,所以我认为这对浏览器的最大并行请求数没有问题.我在这里错过了什么吗?