如果我使用 async:true 启动 ajax 请求,我想知道调用发生时会发生什么。 两个问题:
- 同时触发的其他方法,它们是否已排队?我们能否确定所有这些都将被执行,或者它们是否会在某个时刻超时?
- 如果我点击一个按钮将我重定向到另一个页面,重定向是否会等待 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/