标题是什么。 我试图用AJAX“调用1”运行导入脚本,我想用AJAX“调用2”跟踪导入(用于反馈目的)。 为了给最终用户提供实时反馈,这些调用需要同时运行,“call 2”需要调用自身(递归)来轮询更改。
我有控制器和调用,一切正常,只是不在同一时间。 它是数据库上的软锁还是其他东西?
顺便说一下,我知道ajax调用的“async:true”设置。
[编辑] 看起来Magento阻止我同时执行两个控制器。谁能证实这一点?
答案 0 :(得分:1)
我认为你不能同时做两个AJAX请求。这意味着你总是需要一个逻辑顺序,a.k。首先拨打1'然后拨打2'。如果你想确保在呼叫1之后始终触发呼叫2,只需将其置于成功方法中即可。
像这样:
$.ajax({
url: "test-to-call-1",
context: call-1-context
}).done(function() {
$.ajax({
url: "test-to-call-2",
context: call-2-context
}).done(function() {
Now both ajax requests are done.
And you could add the context of the first one to the second call.
});
});
如果要启用轮询,只需放置一个setTimeOut循环,在其中进行第二次AJAX调用:)
像这样:
function start_polling(counter){
if(counter < 10){ // poll maximum of 10 times.
setTimeout(function(){
counter++;
$.ajax({
url: "test-to-call-2",
context: call-2-context
}).done(function() {
start_polling(counter);
Now both ajax requests are done.
And you could add the context of the first one to the second call.
}).error(function(){
start_polling(counter);
});
}, 1000);
}
}
$.ajax({
url: "test-to-call-1",
context: call-1-context
}).done(function() {
start_polling(0)
});
答案 1 :(得分:1)
好吧我明白了。
所有我必须做的事情是:
session_write_close();
在开始导入的方法前面,我可以用第二次AJAX调用开始轮询!
这可能不赞成,但它有效