For example, I would like to download part of data from the server when I click one button, and downloading other parts in background. How to implement this?
-
1Javascript does not have threadsaaronman– aaronman2013-07-08 20:44:56 +00:00Commented Jul 8, 2013 at 20:44
-
@aaronman , then how to implement that?injoy– injoy2013-07-08 20:45:48 +00:00Commented Jul 8, 2013 at 20:45
-
3Javascript, in browsers, do have threads, now; they're called Web Workers: developer.mozilla.org/en-US/docs/Web/Guide/Performance/…JayC– JayC2013-07-08 20:46:16 +00:00Commented Jul 8, 2013 at 20:46
-
8What you are looking for is called AJAX.Russell Zahniser– Russell Zahniser2013-07-08 20:47:03 +00:00Commented Jul 8, 2013 at 20:47
-
1@aaronman he didn't mention threads. They're but one mechamism of concurrency.cirrus– cirrus2013-07-08 20:47:12 +00:00Commented Jul 8, 2013 at 20:47
|
Show 2 more comments
2 Answers
If you are targetting HTML5 compatible browsers take a look at Web Workers :
http://www.html5rocks.com/en/tutorials/workers/basics/
Background processes with web workers:
Comments
You have only one execution thread, so you will have to play with setInterval() and clearInterval() and execute your code based on timers :
var iv= setInterval(function(){ alert("Running now!"); }, 3000);
Clear the periodic function with :
clearInterval(iv);