javascript - 使用 async : true with ajax, 触发的事件会发生什么

标签 javascript jquery ajax

如果我使用 async:true 启动 ajax 请求,我想知道调用发生时会发生什么。 两个问题:

  1. 同时触发的其他方法,它们是否已排队?我们能否确定所有这些都将被执行,或者它们是否会在某个时刻超时?
  2. 如果我点击一个按钮将我重定向到另一个页面,重定向是否会等待 ajax 完成?或者ajax调用会被中止吗?

最佳答案

The other methods that are triggered in the meanwhile, are they queued? Can we be sure all of them will be executed, or do they timeout at some point?

是的,是的。它们被排队,并且最终总是会被执行。

If I click on a button that redirects me to another page, will the redirection wait for the ajax to finish? Or will the ajax call be aborted?

当从页面重定向时,大多数浏览器都会调用 onerror 回调,状态代码为 0

要获得 JS 事件循环的极其清晰的概述,我强烈推荐 this talk from Philip Roberts .

关于javascript - 使用 async : true with ajax, 触发的事件会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32761718/

相关文章:

javascript - 如何最好地处理 Web 应用程序中的数据验证 : pure javascript code or ajax calls to familiar perl packages?

javascript - 有没有办法获取 Angular $cacheFactory 中的所有键?

javascript - 如何在 JavaScript 运行时、回发之前在单击时立即为光标设置动画

javascript - 为什么我无法通过 jQuery 更改 href 值?

java - 获取 "$ is not defined"

javascript - 如何使用各自的文本框创建多个多范围 slider ?

java - 使用 javascript 进行 Ajax 和 java servlet 数据传输

javascript - Service Worker 和 AJAX

javascript - 在Safari/Chrome中,如何在ready()和focus()上触发函数A,在blur()上触发函数B?

javascript 仅客户端加载通知