如果我在同步 ajax 调用之后进行异步 ajax 调用,会发生什么情况?
我想知道如果我在不同的事件上依次进行 2 个 ajax 调用会发生什么。
比方说,我有两个按钮,单击其中一个按钮时,我会进行阻塞 ajax 调用,假设 2 分钟后返回结果。
单击另一个时,我会进行异步 ajax 调用,该调用平均在 1 分钟后返回。
如果我依次单击按钮 1 和按钮 2,两个 ajax 调用都会发生,还是会停止第二个调用,直到第一个(被阻止的)调用返回?
我觉得如果浏览器连接限制未达到,这两种情况都会发生。 否则,ajax 调用将等待。
我总是可以尝试创建一个简单的页面并对其进行测试,但想知道这里的专家有何感受。
谢谢
I was wondering what will happen if I make 2 ajax calls one after the other on different events.
Lets say, I have two buttons, on click on one , I make a blocking ajax call, which lets say returns the result after 2 minutes.
On the click of the other I make a async ajax call , which returns after an average of 1 minute.
If I click button 1 and button 2 one after the other, would both ajax calls take place, or would the second call be stopped until the first (blocked) one returns?
I feel that both will take place if the browser connection limit has not reached.
Otherwise , the ajax calls will wait.
I can always try creating a simple page and testing this, but want to know , what experts here feel.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同步(阻塞)ajax 调用将阻止您在异步 ajax 调用完成之前启动它。
看看反过来会发生什么可能会更有趣,但话又说回来,我认为我从未在我见过的任何 Web 应用程序中发现过同步 Ajax 调用。 (有充分的理由)
The sync (blocking) ajax call will block you from starting the async ajax call before it finishes.
it might be more interesting to look at what would happen the other way around, but then again, i don't think i've ever uncovered synchronous Ajax calls in any web application i have seen. (with good reason)
如果点击第一个按钮是同步ajax调用,你将无法点击第二个按钮。浏览器会阻止绑定到按钮的同步 ajax 调用。
You will not be able to click on the 2nd button if the click on the 1st button is synchronous ajax call. The browser blocks on synchronous ajax calls that are bind to a button.