转义 $(“html”).ajaxError() 在其中一个 $.ajax() 调用中

Escape $("html").ajaxError() in one of the $.ajax() call

本文关键字:一个 调用 ajax ajaxError html 转义 在其中      更新时间:2023-09-26
$("html").ajaxError(function (event, jqXHR, ajaxSettings, thrownError){
  //show proper message based on error.
});

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

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

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