1

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?

7
  • 1
    Javascript does not have threads Commented Jul 8, 2013 at 20:44
  • @aaronman , then how to implement that? Commented Jul 8, 2013 at 20:45
  • 3
    Javascript, in browsers, do have threads, now; they're called Web Workers: developer.mozilla.org/en-US/docs/Web/Guide/Performance/… Commented Jul 8, 2013 at 20:46
  • 8
    What you are looking for is called AJAX. Commented Jul 8, 2013 at 20:47
  • 1
    @aaronman he didn't mention threads. They're but one mechamism of concurrency. Commented Jul 8, 2013 at 20:47

2 Answers 2

2

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:

http://www.youtube.com/watch?v=VIdkYaLbzMs

Sign up to request clarification or add additional context in comments.

Comments

0

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);

2 Comments

What if the interval is not decided?
You probably have a start condition, so you can check it in the provided function before anything else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.