Ajax: How to prevent jQuery from calling the success event after executing xmlHttpRequest.abort();

后端 未结 6 1250
一个人的身影
一个人的身影 2020-12-31 16:34

Using jQuery\'s $.ajax() function. Wherether the request has been purposely aborted, or if the server is down (not responding) it appears the same outcome happens;

6条回答
  •  滥情空心
    2020-12-31 17:02

    You should set up an error handler, which will get called if the request fails. If you want to abort the request on the server, you could just return some value that you can check for in your success handler, or you could throw an exception from the server. jquery.ajax()

    EDIT: You may want to look into this AJAX Queue/Cache/Abort/Block Manager v. 2.0 (link). It will allow you to run a function after a request has been aborted.

提交回复
热议问题