[英]Execute a javascript function in Asynchronous mode
We have AJAX calls to hit a URL. 我们有AJAX调用来命中URL。 Do we have option to run/execute JavaScript function in Asynchronous mode? 我们是否可以选择在异步模式下运行/执行JavaScript函数?
Note: setTimeout() will execute that function after some seconds but still that will execute in Synchronous mode. 注意:setTimeout()将在几秒钟后执行该函数,但仍将在同步模式下执行。
No. JavaScript runs in a single thread per page. 否。JavaScript每页在一个线程中运行。
You want HTML5 Web Workers . 您需要HTML5 Web Workers 。 There's a good introduction on HTML5 Rocks. 关于HTML5 Rocks 有很好的介绍 。
However, the Google Gears plugin provides a
WorkerPool
:
但是,Google Gears插件提供了
WorkerPool
:
The WorkerPool API allows web applications to run JavaScript code in the background, without blocking the main page's script execution.WorkerPool API允许Web应用程序在后台运行JavaScript代码,而不会阻止主页脚本的执行。
There's also
a proposal by the Gears team to add this to HTML5.
Gears小组还有
一项建议将其添加到HTML5中。
Most modern browsers implement JavaScript Web Workers, they provide a simple way to run scripts in background threads. 大多数现代浏览器都实现JavaScript Web Worker,它们提供了一种在后台线程中运行脚本的简单方法。
Check the following articles: 检查以下文章:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.