jQuery的阿贾克斯,我怎么正确地处理HTTP 408错误?正确地、错误、我怎么、阿贾克斯

2023-09-10 19:35:30 作者:゛__那些画面〞

我做一个jQuery Ajax调用的错误选项进行设置。在我的错误的方法,我想从一个普通的HTTP 500不同的方式处理一个HTTP 408。

现在的问题是,该jxhr.status code是0和身份的价值简直是错误!但在萤火,我可以看到,服务肯定返回的状态code 408。

为什么会jxhr.status code为0?有另一种方法来确定一个HTTP 408错误?

我的错误处理程序code如下所示(对于一个408错误code只持续到其他块):

 错误:函数(jxhr,状态,错误){
。VAR $消息= element.next()找到('。loadmask-MSG-标签);
如果(jxhr.status == 401)
  $ message.html(settings.unauthorizedMessage);
否则,如果(jxhr.status == 408)
  $ message.html(settings.timeoutMessage);
其他
  $ message.html(settings.errorMessage);
 

解决方案

问题是Firefox浏览器。除了火狐任何浏览器的状态code是408在Firefox中的地位code为0,且没有响应的头返回。此外,火狐似乎重新请求10倍的408响应,因为,我不知道为什么!而这仅仅是一个HTTP 408响应。

在最后,我们必须与自定义标题返回一个HTTP 500错误。

肮脏:(

WIN7 IIS7 Service Unavailable HTTP Error 503. The service is unavailable.

I do a JQuery Ajax call with the "error" option set. In my "error" method I would like to handle an HTTP 408 differently from a normal HTTP 500.

The problem is that the jxhr.statusCode is 0 and the "status" value is simply "error"! But in firebug I can see that the service definitely returned status code 408.

Why would the jxhr.statusCode be 0? Is there another way to identify an HTTP 408 error?

My error handler code looks as follows (for a 408 error the code just continues into the 'else' block):

error: function (jxhr, status, error) {
var $message = element.next().find('.loadmask-msg-label');
if (jxhr.status == 401)
  $message.html(settings.unauthorizedMessage);
else if (jxhr.status == 408)
  $message.html(settings.timeoutMessage);
else
  $message.html(settings.errorMessage);

解决方案

The problem was FIREFOX. In any browser except Firefox the status code is 408. In Firefox the status code is 0, and no response headers are returned. Also, Firefox seems to re-request 10 times because of the 408 response, I have no idea why! And this is only for an HTTP 408 response.

In the end we had to return a HTTP 500 error with custom headers.

Dirty :(