Jquery: is there an error handler for $ .post in jQuery?

When $ .post succeeds, there is a success handler for it. What happens if it fails? Is there a similar handler that we can use for this case, so that we can tell the user that something is not happening correctly?

+4
source share
2 answers

According to the documentation, there is no special error handler for the $.post method.

What you need to do if you want to have both success and failure handlers is to use the low-level $.ajax method. The documentation can be found here: http://api.jquery.com/jQuery.ajax/

 $.ajax({ type: "POST", url: "some.php", success: function(html){ /* Do success stuff here */ }, error: function(){ /* do error stuff here */ } }); 
+3
source

You can catch it with . ajaxError () , but this applies to all ajax requests in your application. You also need to make sure that you send back the HTTP error status to the front end that jQuery will capture.

0
source

Source: https://habr.com/ru/post/1309939/


All Articles