[英]simultaneous ajax requests django
我在頁面加載時觸發了多個ajax調用。
從request1
我期望response1
,從request2
我期望response2
。 但是我同時收到request1
和request2
response1
。
當我在收到response1
之后將request2
觸發時,便按預期接收了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()
您可能想研究AjaxQ(http://code.google.com/p/jquery-ajaxq/),它使您可以鏈接ajax調用而在給定時間內沒有重疊。
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.