【问题标题】:What is ajax error?什么是ajax错误?
【发布时间】:2025-12-18 20:55:01
【问题描述】:

什么服务器响应导致浏览器 Ajax 处理程序出现 ajaxError? 这个错误码和 200 不同还是不是空的特殊 json 字段?

【问题讨论】:

    标签: javascript ajax jquery client-server


    【解决方案1】:

    是的,非 200 响应代码可能导致错误,you can see what constitutes "success" here:

    httpSuccess: function( xhr ) {
        try {
            // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
            return !xhr.status && location.protocol === "file:" ||
                xhr.status >= 200 && xhr.status < 300 ||
                xhr.status === 304 || xhr.status === 1223;
        } catch(e) {}
    
        return false;
    }
    

    这是从 jQuery 1.4.4 开始的,之前的状态代码 0 也是成功的,因为 Opera 304 被报告为 0...此后宽大处理已被删除以消除误报成功。如果上面的检查是falsethe error handler is called

    【讨论】: