开发者

Is there a bug with Google Chrome and JQuery ajaxStop

Maybe I'm using the JQuery ajaxStop event incorrectly, but it doesn't trigger for me in Google Chrome. Here is my code:

if($("#calculateButton").length > 0) {
    console.log("Setting calc button event");

    $("#calculateButton").ajaxStop(function() {
        console.log("calculate on ajax stop");
        $(this).unbind('ajaxStop');
        $(this).click();
    });

    console.log("Sending test AJAX request");
    $.ajax({
       type: "POST",
       url: "Backend/getcustomerrate.php",
       success: function() {
           console.log("AJAX request finished");
       }
    });

    //this is what I had before testing
    //Loading.loadOldQuote(qn, Loading.FOOTER);
} else {
    console.log("Could not find calculate button");
    setProgress("FATAL ERROR: Could not find calculate button");
}

The following is my console output:

Setting calc button event

Sending test AJAX request

AJAX request finished

I'm confused. Shouldn't this have triggered the .ajaxStop event?

EDIT: The same code triggers the relevant event in Firefox, which is what I primarily use for testing.

EDIT2: There may be other AJAX requests running at the same time, but those AJAX requests do finish eventually. I left the page open for a while with the console on, and the expected message ('calculate on AJAX stop') did not come up.

EDIT3: Thanks, everyone. It turns o开发者_JAVA技巧ut that Chrome halts script execution when it finds an error, and does not print anything to the console if it does. The error is not triggered in Firefox.


I created a quick jsfiddle and it seems to work.

Are there any other ajax requests that are being called at the same time or during the initial request?

According to the documentation:

Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the ajaxStop event.

If there is anything else running, this event won't fire. Is this something that you could do in the success function of the ajax request instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜