0

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

1 に答える 1

0

AjaxQ (http://code.google.com/p/jquery-ajaxq/) を調べると、特定の時間内に重複することなく ajax 呼び出しを連鎖させることができます。

それが役に立てば幸い

于 2013-01-21T23:05:46.913 に答える