简体   繁体   English

jQuery $ .ajax在错误处理程序中返回未定义的jqXHR

[英]Jquery $.ajax returning undefined jqXHR in error handler

I have the following Ajax call: 我有以下Ajax电话:

$.ajax({
        type: 'POST',
        contentType: 'application/json',
        url: reply_url,
        data: reply_data,            
        success: function(data, textStatus, xhr) {
          location.reload();
        },
        error: function(jqXHR, exception) {
          alert(jqXHR.status);
        }
      });

And I'm getting the following error when the server returns 500: 服务器返回500时出现以下错误:

Uncaught TypeError: Cannot read property 'status' of undefined 

What are the cases where jqXHR could be undefined? 在什么情况下无法定义jqXHR?

PS: I'm using Jquery v1.8.3 PS:我正在使用Jquery v1.8.3

EDIT: 编辑:

I noticed that this happens only in Ajax calls to my Ruby on Rails application. 我注意到,这仅发生在对我的Ruby on Rails应用程序的Ajax调用中。 Ajax calls to another domains returns jqXHR as exptected. 对其他域的Ajax调用将返回jqXHR,如预期的那样。

As you can see here: http://jsbin.com/rajusolu/1/edit?js,output 如您所见: http : //jsbin.com/rajusolu/1/edit?js,输出

your request function does actually work.... (I tested it also with jQuery 1.8.3 and works fine). 您的请求函数确实起作用了...。(我也使用jQuery 1.8.3对其进行了测试,并且工作正常)。 If you want to try that link remember to select "Add library" > "jQuery". 如果您想尝试该链接,请记住选择“添加库”>“ jQuery”。

If you see that error then is something related to some other part of your code, because the snippet you provided works fine. 如果看到该错误,则与代码的其他部分有关,因为您提供的代码片段运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM