首页 > 解决方案 > 当通常的错误字段为空时,我们还能找到更多关于 jQuery .ajax() 失败的原因?

问题描述

var request = $.ajax({
    url: url,
    method: "POST",
    dataType: "json",
    timeout: 5000,
    error: function (jqXHR, exception, errorThrown) {
           
        // in the case which I am trying to debug ...

        console.log(jqXHR.status);
        // Outputs a 0 - not useful, general purpose 'network is down' and 3 other reasons

        console.log(jqXHR.statusText);
        // Outputs "error" - not useful

        console.log(jqXHR.responseText);
        // Outputs "undefined" - not useful

        console.log(exception);
        // Outputs "error" - not useful

        console.log(errorThrown);
        // Outputs "" - not useful

    });

有什么方法可以获取更多关于出了什么问题的信息?

When jqXHR.statusis 0,这意味着主机无法访问,但问题是,它正在连接到它在几毫秒前获取 Javascript 的完全相同的主机(在相同的https协议上),所以它真的不太可能关闭 - 别的发生了。

谢谢大家,注意安全。

编辑:

标签: javascriptjqueryajaxerror-handling

解决方案


推荐阅读