简体   繁体   中英

Execute a javascript function in Asynchronous mode

We have AJAX calls to hit a URL. Do we have option to run/execute JavaScript function in Asynchronous mode?

Note: setTimeout() will execute that function after some seconds but still that will execute in Synchronous mode.

No. JavaScript runs in a single thread per page.

You want HTML5 Web Workers . There's a good introduction on HTML5 Rocks.

However, the Google Gears plugin provides a WorkerPool :

WorkerPool API

The WorkerPool API allows web applications to run JavaScript code in the background, without blocking the main page's script execution.

There's also a proposal by the Gears team to add this to HTML5.

Most modern browsers implement JavaScript Web Workers, they provide a simple way to run scripts in background threads.

Check the following articles:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM