可以同步(阻塞)Ajax调用块浏览器的用户界面? [英] can a synchronous (blocking) ajax call block the browser's UI?

查看:103
本文介绍了可以同步(阻塞)Ajax调用块浏览器的用户界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是jQuery的导向,但不一定完全。

This question is jQuery oriented, but not necessarily exclusively.

简短的问题:

可以同步Ajax调用块从一个普通按钮被点击的?我testings表明它不会发生,但也许另一个浏览器发出的问题。

Can synchronous ajax call block a normal button from being clicked on? My testings show it doesn't happen, but maybe another browser makes problems.

长问题:

在另外一个问题我问过,的如何阻止对AJAX调用(我想它阻止),男生们说,浏览器会在某些情况下阻止。

In another question I've asked, how to block on ajax call (I want it to block), the guys said that the browser will block in some cases.

其实连文档的jQuery的说: 请注意,同步请求可能会暂时锁定浏览器,禁用任何行动,同时请求被激活。

Actually even the docs of jQuery say: Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

我想:
1。了解如何/为什么这会发生。
2。评估这种可能性发生。

I'm trying to:
1. Understand how/why that would happen.
2. Assess the probability of that to happen.

这是我的理解,这可能是不正确的:
我想,锁定将发生在页面的UI,如果我作为dev的,没有建立/更新AJAX调用本身,它的块的JavaScript虚拟机前的用户界面,从而延缓了用户界面生成/更新。正确与否?

From my understanding, which might be incorrect:
I imagine that "locking" will happen to the page's UI if I, as the dev, didn't build/update the UI before the ajax call itself, which "blocks" the javascript VM, thus delaying the UI build/update. Correct or not?

推荐答案

是的,它会的。虽然同步请求未完成,浏览器等待其返回。这种情况发生的概​​率是100%,但如果你的要求返回速度不够快,这可能不是那么明显。事情是,你不能要求返回快速计数。

Yes it will. While a synchronous request is outstanding, the browser waits for it to return. The probability of that happening is 100%, but if your request returns fast enough, it might not be that noticeable. Thing is, you can't count on a request returning quickly.

这就是AJAX调用点。第一个 的意思是异步的,这意味着,不堵。

That's the point of ajax calls. The first a mean asynchronous, which means, "doesn't block".

因为Ajax调用是异步的,你的code可以在任何地方时请求返回,这意味着你需要一种方法来处理时,该请求并返回响应。这就是为什么你使用的回调的处理响应。

Since ajax calls are asynchronous, your code can be anywhere when the request returns, which means you need a way to handle the response when the request does return. That is why you use callbacks to handle the response.

你为什么不试一试呢?

这篇关于可以同步(阻塞)Ajax调用块浏览器的用户界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆