在下面的 javascript 中,我想根据 http 错误代码处理错误。可以处理所有其他类型的 http 错误,但不能处理 407,当服务器发送状态为 407 时,jqXHR.status 显示为“0”而不是“407”。知道为什么它不显示状态为 407 吗?是否有任何替代方法来处理客户端的 407 错误。
function handleError(jqXHR) {
if (jqXHR.status === 500) {
// Server side error
} else if (jqXHR.status === 404) {
// Not found
} else if (jqXHR.status === 407) {
// Proxy Authentication is required
// This is not working, when server send http status code as 407, client side it is recieved as 0
}
}
最佳答案
您可以测试 jqXHR.readyState 并处理“UNSENT”状态。 (参见此处:https://xhr.spec.whatwg.org/#xmlhttprequest)因此,您可以处理“未发送”状态,而不是处理“需要身份验证”状态。
关于javascript - 在 jquery 中处理 http 错误 407(需要代理身份验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49106730/