ajax就绪状态达到4,但状态始终为200

ajax就绪状态达到4,但状态始终为200,ajax,jsp,servlets,safari,onreadystatechange,Ajax,Jsp,Servlets,Safari,Onreadystatechange,我的ajax代码是: xhr.onreadystatechange = function() { if (xhr.readyState == 4) { alert(xhr.status); if (xhr.status == 200) { alert("200"); } else if (xhr.status == 8001) { alert("

我的ajax代码是:

 xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        alert(xhr.status);
        if (xhr.status == 200) {
            alert("200");               
        }
        else if (xhr.status == 8001) {
            alert("8001");               
        }
        else if (xhr.status == 8000) {
            alert("8000");             
        }
        else if (xhr.status == 7000) {
            alert("7000");                
        }
        else {
            alert("x");              
        }
    }
};
xhr.open("POST","URL",true);
xhr.send(null);
我在xhr.open中提到的页面中的代码是:

    if (request.getSession().getAttribute("SATI_UID") == null) {
        response.sendError(8000);
    } else {
            response.sendError(8001);
    }
它可以在firefox、chrome和ie中使用,但在safari中,我总是获得状态200。 我使用safari 5.1.7。我也使用response.setStatus而不是response.sendError,但它不起作用。
有人知道为什么会发生这种情况吗?

您需要在servlet上设置响应服务器端的状态

AJAX客户机将获得响应并将状态代码存储在服务器上

它应该是有效的

不要忘记在提交响应和发送任何头之前必须设置响应代码

您可能希望使用或这样做


或者,您可能希望在web.xml上定义一个错误页。检查:

我认为这是因为您使用的是非标准http法规。您应该抛出正确类型的4xx或5xx错误,请参见,因为此代码在中具有实际意义,然后在响应主体中设置您自己的错误自定义代码

总之,http响应的状态代码不应用于发送您自己的状态代码,因为它破坏了协议,并可能导致中间件服务器(例如缓存服务器)出现一些问题