Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

waiting in javascript

Status
Not open for further replies.

rravenn

Programmer
Jul 6, 2004
40
US
I need to wait for a specific set of evnets to happen before I do something (it's multiple xmlhttprequests and I need them all to be finished and some processing to take place).
Here's how I do it:

while (this.resources.find( function(v,i) { return v.state < 2 } )) { alert("test"); }

(.find is prototype.js thing that finds an element in some collection according to the function result, I tried to replace it with common for loop and the problem persists).

With alert(as shown here) everything works - I click ok, by that time all requests are loaded and the code continues; without alert, however, firefox hangs and (I suppose) the code that handles xmlhttp request completion never fires, state is never set (it's a custom field I defined) so the browser is dead.

Is there any way to set a delat in javascript? I know of settimeout but its application here would be really ugly...
 
setTimeout is really the best method to use if you need a delay. Using while or for, or any other loop statement cn csuse your browser to appeawr to lock up, due to the tight loop running.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yeah that's the problem ;)
So there's no way to add a delay inside a loop?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top