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?
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
If 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)