admin管理员组文章数量:1418303
I have a jQuery AJAX post request that is unexpectedly triggering the error
callback instead of success
. One random suspicion I have is the 302 status code it is receiving, although that may be wrong.
I looked at the documentation, but I feel like one thing is a bit unclear: What is jQuery's definition of a successful request?
I have a jQuery AJAX post request that is unexpectedly triggering the error
callback instead of success
. One random suspicion I have is the 302 status code it is receiving, although that may be wrong.
I looked at the documentation, but I feel like one thing is a bit unclear: What is jQuery's definition of a successful request?
Share Improve this question asked Jun 22, 2012 at 15:11 Brad KochBrad Koch 20.4k20 gold badges112 silver badges140 bronze badges 7- I think that when there is HTTP 200 response. – jcubic Commented Jun 22, 2012 at 15:13
- 1 if it's not a 4xx/5xx code, basically. 3xx it should just follow the redirect then work with the code the new url returns, 2xx means http success anyways. – Marc B Commented Jun 22, 2012 at 15:13
- I thinx 2xx and 3xx responses are success. But can't approve it. – Ruben Nagoga Commented Jun 22, 2012 at 15:14
- 3 If the response is 2xx or 3xx AND the returned data matches the expected dataType and is valid, the response should be considered a success – Kevin B Commented Jun 22, 2012 at 15:16
-
2
For those who can't see my answer (now deleted) it pointed out a line of code (
if ( status >= 200 && status < 300 || status === 304 )
) from the jQuery source. But there's more to it than just the status code, as @KevinB stated previously. – James Allardice Commented Jun 22, 2012 at 15:23
1 Answer
Reset to default 8If the response is between 199 and 300 ( >= 200 and < 300 ) or equal to 304 and the responseText can be successfully converted to the dataType that you provide (text by default), it is considered a successful request.
For example, if you return JSON and you get a 200 response status but it fails, it is more than likely a JSON parser problem meaning your JSON is not valid.
If you are returning HTML or XML and it fails with a 200 response status, the responsetext couldn't be converted to HTML or XML respectively (monly happens in IE with invalid html/xml)
本文标签: javascriptWhat responses does jQueryajax consider to be quotsuccessquotStack Overflow
版权声明:本文标题:javascript - What responses does jQuery.ajax consider to be "success"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745250929a2649817.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论