Javascript 异步在 Ajax 中意味着什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3393751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:26:51  来源:igfitidea点击:

What does Asynchronous means in Ajax?

javascriptajaxasynchronous

提问by JCX

What does Asynchronous means in Ajax? and also how does Ajax know when to pull data without server polling?

异步在 Ajax 中意味着什么?以及 Ajax 如何知道何时在没有服务器轮询的情况下提取数据?

回答by Mchl

Asynchronous means that the script will send a request to the server, and continue it's execution without waiting for the reply. As soon as reply is received a browser event is fired, which in turn allows the script to execute associated actions.

异步意味着脚本将向服务器发送请求,并在不等待回复的情况下继续执行。一旦收到回复,就会触发浏览器事件,这反过来又允许脚本执行相关的操作。

Ajax knows when to pull data from server, because you tell it when to do it.

Ajax 知道什么时候从服务器拉取数据,因为你告诉它什么时候做。

回答by fastcodejava

Just about what it means in any other context. When you make an ajax call, it doesn't block until it returns.

几乎在任何其他上下文中都意味着什么。当您进行 ajax 调用时,它不会阻塞,直到它返回。

回答by lborgav

Browsers do not give access to threading model, so we have just a single thread to handle the User Interface. So, all the modifications in the application is in the same thread.

浏览器不允许访问线程模型,因此我们只有一个线程来处理用户界面。因此,应用程序中的所有修改都在同一个线程中。

Fortunately, the browsers exposes several async API's, like XHR(XMLHttpRequest), also known as AJAX. When you register a event handler for some object, the action for this object will be executed in another thread and the browser will trigger the event in the main thread.

幸运的是,浏览器公开了几个异步 API,例如 XHR(XMLHttpRequest),也称为 AJAX。当您为某个对象注册事件处理程序时,该对象的操作将在另一个线程中执行,浏览器将在主线程中触发该事件。

So async mean that the browser won't wait for when the main thread is free to perform the action

所以 async 意味着浏览器不会等待主线程空闲来执行操作

回答by Mandeep Kaur

Asynchronous (in Ajax) processes incoming requests in a constant event stack and sends small requests one after the other without waiting for responses. In other words, asynchronous ajax call allow the next line of code to execute, whereas synchronous call stop JavaScript execution until the response from server.

异步(在 Ajax 中)在一个恒定的事件堆栈中处理传入的请求,并一个接一个地发送小请求,而无需等待响应。换句话说,异步 ajax 调用允许执行下一行代码,而同步调用停止 JavaScript 执行,直到来自服务器的响应。