Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to tell ajax success from ajax error?


Asked by Aniya Stuart on Nov 28, 2021 AJAX



.ajaxError () will be triggered no matter which request is completed. Next thing you want to know is to tell apart from each requests, you can use the parameter settings.url to distinguish different urls.
And,
success: The success function is called if the Ajax request is completed successfully. i.e. If the server returns a HTTP status of 200 OK. If our request fails because the server responded with an error, then the success function will not be executed. error: The error function is executed if the server responds with a HTTP error.
Furthermore, If none are in progress, jQuery triggers the ajaxStart event. If $.ajax () or $.ajaxSetup () is called with the global option set to false, the ajaxStart () method will not fire. Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests.
Consequently,
‘Complete’ means it has run but could have an error. ‘Success’ means the Ajax was successful. You can ‘stack’ them to handle either situation. ‘Error’ is useful so they know an error took place. These are all event handlers, or event callbacks, that take place after an Ajax request.
In addition,
The errormethod of jQuery's ajaxfunction will only get called when the page requested returns an error status code. Your example will probably return HTTP 200, which is why successgets called; jQuery does not interrogate the contents of a response to determine whether or not it was successful.