简体   繁体   English

AJAX状态码<400成功吗?

[英]Success with AJAX Status code < 400?

Basically it boils down to, is there any case where it would be bad for me to call the success callback function on status codes under 400? 基本上它归结为,有没有哪里会了我400下呼吁状态码的成功回调函数的案例?

In looking at the list of status codes for HTTP , I don't think there would be but I want to make sure. 在查看HTTP的状态代码列表时 ,我认为不会有,但我想确定。 I don't think I'll be getting 1XX level codes as they look like most of them return before the full request is processed and readyState === 4 (I don't care about IE 7's 122). 我不认为我会得到1XX级代码,因为他们看起来大部分代码在处理完整请求之前返回并且readyState === 4 (我不关心IE 7的122)。 And I want to still return success on a 302 and 304 status codes. 我仍希望在302和304状态代码上恢复成功。 So is status < 400 an acceptable way to catch all of this? status < 400是一种可以接受所有这一切的可接受方式吗?

A 301 means the client is responsible for making the HTTP call again with the new URL. 301表示客户端负责使用新URL再次进行HTTP调用。 Does your library or toolkit already handle this for you? 您的图书馆或工具包是否已为您处理此问题?

Building on @sarnold's concerns , it looks like the XMLHttpRequest specifications say the following: 基于@sarnold的担忧 ,看起来XMLHttpRequest规范说明如下:

If the response is an HTTP redirect (status code 301, 302, 303 or 307), then it MUST be transparently followed (unless it violates security or infinite loop precautions). 如果响应是HTTP重定向(状态代码301,302,303或307),则必须透明地遵循(除非它违反安全性或无限循环预防措施)。 Any other error (including a 401) MUST cause the object to use that error page as the response. 任何其他错误(包括401)必须使对象使用该错误页面作为响应。

Which seems to indicate to me that either 2XX or 3XX responses are valid. 这似乎向我表明2XX或3XX响应是有效的。 So, in short, my findings indicate status < 400 is an appropriate status response check. 因此,简而言之,我的发现表明status < 400是一个适当的状态响应检查。

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

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