How does ajax call terminate when window closed or refreshed too fast as example at stackoverflow voting calls?

守給你的承諾、 提交于 2019-12-25 09:35:12

问题


As I asked in this meta question: https://meta.stackexchange.com/questions/119259/voting-is-lost-due-to-ajax-call-latency

I wonder about issue, how it occurs?

Is it because browser sends a notification that it says I gave upor
is it because it is really fast action by user that browser even could not send the xhr request?


回答1:


I'd guess that the request is sent, but that browsers cancel XHR pending requests when a page is unloaded.

XHR requests can be canceled manually via the .abort() method, so it wouldn't surprise me if pending requests are aborted.




回答2:


I guess it is because browser was not able to initiate xhr request. Once xhr request get initiated, it doesn't matter whether you are on same page (or) left. There may be sometime consuming calculations before initiating xhr while you click on voting button, if your next action (move to next page or something like that) is that much quicker (where these calculations couldn't complete), your request xhr request might not have initiated.



来源:https://stackoverflow.com/questions/8886099/how-does-ajax-call-terminate-when-window-closed-or-refreshed-too-fast-as-example

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