What's the point in the abort function in JavaScript?
Why would I ever need t开发者_开发问答o use it?
If you just kicked off an asynchronous request that could take some time... or perhaps update a portion of the UI, then there are cases when a user action could invalidate that one. In that scenario you would want to simply cancel the pending XHR request so further processing doesn't happen.
Auto complete is a good example of this. The user finishes a character and after some small amount of time you begin to fetch the results. However, if the user starts typing again, then you can simply cancel that request in order to free up bandwidth for the next fetch.
It's a method of XMLHttpRequest and allows you to abort an Ajax request. It is used when the server has not yet answered your Ajax request but you don't need the result any more, for example because the user closed the dialog that was waiting for data.
精彩评论