【问题标题】:Is there a bug with Google Chrome and JQuery ajaxStopGoogle Chrome 和 JQuery ajaxStop 是否存在错误
【发布时间】:2011-07-29 14:20:32
【问题描述】:

也许我错误地使用了 JQuery ajaxStop 事件,但它不会在 Google Chrome 中为我触发。这是我的代码:

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");
}

以下是我的控制台输出:

设置计算按钮事件

发送测试 AJAX 请求

AJAX 请求完成

我很困惑。这不应该触发 .ajaxStop 事件吗?

编辑:相同的代码在 Firefox 中触发相关事件,这是我主要用于测试的。

EDIT2:可能有其他 AJAX 请求同时运行,但这些 AJAX 请求确实最终完成。我在控制台打开的情况下将页面打开了一会儿,但没有出现预期的消息(“在 AJAX 停止时计算”)。

EDIT3:谢谢大家。事实证明,Chrome 在发现错误时会暂停脚本执行,并且不会在控制台打印任何内容。 Firefox 不会触发该错误。

【问题讨论】:

    标签: jquery ajax google-chrome


    【解决方案1】:

    我创建了一个快速的jsfiddle,它似乎有效。

    是否有任何其他 ajax 请求同时或在初始请求期间被调用?

    根据documentation

    每当一个 Ajax 请求完成时,jQuery 都会检查是否还有其他未完成的 Ajax 请求。如果没有剩余,jQuery 会触发 ajaxStop 事件。

    如果还有其他东西正在运行,则不会触发此事件。您可以在 ajax 请求的 success 函数中执行此操作吗?

    【讨论】:

    • 不,因为我有大量可变数量的 AJAX 请求。当这个简单的函数起作用时,创建一个复杂的框架是没有意义的。直接在 Google Chrome 中试用,看看会发生什么。
    猜你喜欢
    • 2020-01-27
    • 1970-01-01
    • 2012-03-19
    • 2020-08-02
    • 2017-06-28
    • 1970-01-01
    • 2011-05-24
    • 2017-06-25
    • 1970-01-01
    相关资源
    最近更新 更多