views:

393

answers:

3

Anyone can tell me how to activate two (or more) JavaScript AJAX functions in parallel?

A: 

Is this what you're looking for?

setTimeout('JsFunction1(val);', 0); 
setTimeout('JsFunction2(val);', 0);
used2could
This will not execute them in parallel. JsFunction1 will always execute first, no matter what. setTimeout 0 just pushes code to the end of the execution stack.
Rakesh Pai
you can't get anything in JS to actually execute at the EXACT same time but you can get them to execute in an "asynchronous" manner (I know JS is singled threaded so it's not really asynchronous, or at least it wasn't until Chrome came along). WTF is up with you trolling around for this post over two weeks later to make a random comment like that? Who has that kind of time?
used2could
A: 

Window.setTimeout is the function you want to use.

David Basarab
but the problem is its not working parallel , one function after one only...i need some thing like picture in side the below linkhttp://piecesofrakesh.blogspot.com/2009/03/downloading-javascript-files-in.html
Alex
+5  A: 

This is not possible. Javascript can only work in a single thread and there is no way to actually have two functions running in parallel. You need to make one call and then the other. The callbacks of these will be called (not necessarily in the same order with the invocation methods), when data have been returned or an error/timeout occurs. Only when one callback completes, will the second one be allowed to run.

Have also in mind that browsers restrict the number of active ajax calls. So, if you try to make too many ajax calls, one might wait (blocking all javascript code) for other calls to complete.

kgiannakakis