Aborting a jQuery getJSON XMLHttpRequest

て烟熏妆下的殇ゞ 提交于 2019-11-30 05:16:44

Calling abort resets the object; the onreadystatechange event handler is removed, and readyState is changed to 0 (uninitialized).

i do not think it cancels the request itself, it just ignores any response (manipulating the event handler)- but i didnt really try it out yet.

but it will deifnitely allow you to reuse the object - no matter if the browser still has some thread working with the old request.

you may take a look at the JSONP-Plugin With this Plugin you have the ability to manually abort the request. Also take a look at "a cautionary note" at IBM's Technical library:

First and foremost, there is no error handling for JSONP calls. If the dynamic script insertion works, you get called; if not, nothing happens. It just fails silently. For example, you are not able to catch a 404 error from the server. Nor can you cancel or restart the request.

Another great article on handling this is found here: http://www.bennadel.com/blog/1500-Catching-Timeout-Errors-With-jQuery-Powered-AJAX.htm.

I simply converted my .getJSON request to .ajax and added the timeout/error handling.

Thanks!

take a look at the jquery AJAX Queue/Cache/Abort/Block Manager, maybe this can help you to prevent you current situation.

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