4

在下面的 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
  }
}

4

1 回答 1

0

您可以测试 jqXHR.readyState 并处理“未发送”状态。(见这里:https ://xhr.spec.whatwg.org/#xmlhttprequest )因此,您可以处理“未发送”状态,而不是处理“需要身份验证”状态。

于 2018-03-09T12:20:15.387 回答