我有多個ajax調用在頁面加載時觸發。同時ajax請求django
從request1
我希望response1
,並從request2
我期待response2
。但我收到request1
和request2
的response1
。
當我移動request2
後response1
已經收到火,然後我收到request2
如預期。
如何安全地執行多個ajax調用?
一些代碼:
//avoids problem
this.update = function(){
$.post('/ws/newsfeed/', {'action':'6'}).done(function(response){
...
_this.get_alert_count()
})
}
this.get_alert_count = function(){
$.post('/ws/newsfeed/', {'action':'2'}).done(function(count) {
...
})
}
_this.update()
//causes problem
this.update = function(){
$.post('/ws/newsfeed/', {'action':'6'}).done(function(response){
...
})
}
this.get_alert_count = function(){
$.post('/ws/newsfeed/', {'action':'2'}).done(function(count) {
...
})
}
_this.update()
_this.get_alert_count()
如果你不介意,你可以發佈一些示例代碼?這可能會有所幫助! – Mutant
您是否嘗試過運行Firebug來檢查請求和響應,以確保您的JS中沒有錯誤? – Spacedman
@Spacedman使用鉻。我檢查過開發工具是。你可以看到上面的代碼有多簡單 - 沒有錯誤。 – rikAtee