In an ajax success function, is it assumed the status code is 200? or could it be successful if you return 304 or 503?
What actually defines it's successful?
In an ajax success function, is it assumed the status code is 200? or could it be successful if you return 304 or 503?
What actually defines it's successful?
You're correct, jQuery ajax will "fail" if it receives an HTTP 503 ... or 500, or 404, etc. It will also (obviously) fail on ECONNREFUSED or any socket-level (communications) error.
Here is the documentation:
https://api.jquery.com/jquery.ajax/
jQuery.ajax(): Perform an asynchronous HTTP (Ajax) request.
jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
An alternative construct to the error callback option, the .fail() method replaces the deprecated .error() method. Refer to deferred.fail() for implementation details.
https://api.jquery.com/deferred.fail/
deferred.fail(): Add handlers to be called when the Deferred object is rejected.
It's worth noting that the connection can succeed ... the server can return HTTP 200/OK ... and your jQuery Ajax call can STILL trigger a "fail".
For example, if you're expecting a JSON response, and the server returns XML:
https://www.mkyong.com/jquery/jquery-ajax-request-return-200-ok-but-error-event-is-fired/
ADDITIONAL INFO:
To answer your original question: Yes, "success" generally implies an HTTP 200.
But a lot of different things besides a non-HTTP 200 can trigger a "fail".
You can even have an HTTP 200 and still "fail" (per the link above).
Or have a non-HTTP 200 and still "succeed" (for example, HTTP 201).
Q: Is your question answered?