【问题标题】:Escape $("html").ajaxError() in one of the $.ajax() call在 $.ajax() 调用之一中转义 $("html").ajaxError()
【发布时间】:2012-03-20 11:06:54
【问题描述】:
$("html").ajaxError(function (event, jqXHR, ajaxSettings, thrownError){
  //show proper message based on error.
});

我还使用来自 catch 块和 window.onerror 函数的 $.ajax() 将 JavaScript 错误发送到服务器。如果这两个调用失败,我不希望它出现在 ajaxError 处理程序之上。

【问题讨论】:

  • 你能更好地解释你的问题吗?目前尚不清楚问题是什么。
  • @Tim 理解正确。

标签: javascript jquery error-handling


【解决方案1】:

第一个错误处理程序将捕获 jQuery 的 ajax 函数抛出的所有异常。如果您不希望它处理异常,我建议检查 ajax 请求的 URL 以查看它是否属于您的 JS 错误处理脚本,如果是,请忽略它。

$("html").ajaxError(function (event, jqXHR, ajaxSettings, thrownError){
    if (ajaxSettings.url.substring(0,len)=='http://www.example.com/logJSError') {
        return;
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多