jquery: is there a fail handler for $.post in Jquery?

故事扮演 提交于 2019-12-05 11:56:10

There is not, according to the documentation, a specific error handler for $.post method.

What you have to do, if you want to have both the success and fail handlers, is to use the low-level $.ajax method. It's 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 */
  }
});

You can catch it using .ajaxError(), but this applies to all ajax requests in your application. You also need to make sure you send back a HTTP error status back to the front end to be captured by jQuery.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!