ページの読み込み時に複数の 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()