我在页面加载时触发了多个 ajax 调用。
从request1我期待response1,从request2我期待response2。response1但我同时收到request1和request2。
当我收到request2后开始射击时,我按预期收到了。response1request2
如何安全地进行多个 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()