当窗口关闭或刷新太快时,ajax 调用如何终止(例如 stackoverflow 投票调用)?
正如我在此元问题中所问:https://meta. stackexchange.com/questions/119259/voting-is-lost-due-to-ajax-call-latency
我想知道这个问题,它是如何发生的?
是因为浏览器发送了一条通知,显示我放弃了
还是
是不是因为用户动作太快,浏览器甚至无法发送xhr
请求?
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 up
or
is it because it is really fast action by user that browser even could not send the xhr
request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜想请求已发送,但浏览器会在页面卸载时取消 XHR 待处理请求。
XHR 请求可以通过
.abort()
方法手动取消,因此如果挂起的请求被中止,我不会感到惊讶。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.我猜这是因为浏览器无法发起xhr请求。一旦 xhr 请求启动,无论您是否在同一页面(或左侧)都无关紧要。当您单击投票按钮时,在启动 xhr 之前可能会进行一些耗时的计算,如果您的下一步操作(移至下一页或类似的操作)快得多(这些计算无法完成),您的请求 xhr 请求可能不会已发起。
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.