jQuery的$。获得/ $。AJAX通过HTTP状态code 200,而不是预期的状态$ C $ 201或202Ç [英] jQuery $.get/$.ajax passes HTTP status code 200 instead of expected status code of 201 or 202

查看:434
本文介绍了jQuery的$。获得/ $。AJAX通过HTTP状态code 200,而不是预期的状态$ C $ 201或202Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经返回HTTP状态code 200,201,和202相同的URL服务器。在Chrome中,我已经证实的网络调试面板的状态code是什么,我希望它是(如200,201或202)。我靠,该状态code,以决定下一步。

I've a server that returns HTTP status code 200, 201, and 202 from the same url. In Chrome, I've confirmed with the Network debugging panel that the Status Code is what I expect it to be (i.e. 200, 201 or 202). I rely on that status code to determine the next step.

我想到的是,回调的jQuery(1.5.2版本)AJAX请求设置 jqxhr.status 到服务器发送的状态code。但是,状态code是总是200,即使由服务器发送的code是201或202。

I'd expect that the callbacks for jQuery (version 1.5.2) AJAX requests to set jqxhr.status to the status code that the server sends. However, the status code is always 200, even if the code sent by the server is 201 or 202.

在换句话说,下面的code打印 code:200 ,无论什么样的服务器发送

In other words, the following code prints Code: 200 regardless of what the server sends.

$.get(url, {}, function (data, textStatus, xhr ) {
    alert("Code: " + xhr.status);
});

这是怎么回事,更重要的是,一个人如何能得到的实际状态code在一个jQuery AJAX回调 $。获得 $。阿贾克斯

感谢您的阅读。

推荐答案

这是我所经历过的jQuery只是没有设置很好地处理实际状态codeS的响应。您可以尝试只是在做一个人工AJAX调用使用一些好老光秃秃的骨头JS和处理自己的状态。

From what I have experienced jQuery is just not set up very well for handling actual status codes in the response. You can try just doing a manual AJAX call using some good old bare bones JS and handle the status yourself.

下面是关于如何做到这一点的几个教程。

Here are a few tutorials on how to do so.

http://www.degraeve.com/reference/simple-ajax-使用example.php

http://www.w3schools.com/ajax/default.asp

request.status是你应该能够访问状态code。在您的要求的对象。这里是另一个页面显示有关如何访问有关请求的状态更为细致的一点点信息。

request.status is where you should be able to access the status code in your request object. Here is another page showing a little bit about how to access even more granular information about the status of the request.

http://www.ibm.com/developerworks/web/library / WA-ajaxintro3 /

希望帮助你钉了!

这篇关于jQuery的$。获得/ $。AJAX通过HTTP状态code 200,而不是预期的状态$ C $ 201或202Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆