ページの読み込み時に複数の ajax 呼び出しが発生しています。
request1
私が期待するからresponse1
、そしてrequest2
私が期待するからresponse2
。しかし、私はresponse1
と の両方request1
を受け取りrequest2
ます。
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()