colandy Posted April 25, 2007 Share Posted April 25, 2007 I have an AJAX Chat app running and the acompanying javascript calls the the AJAX object very 2 seconds, however I now need to run another object within the same web page that calls the new AJAX object every 5 seconds while still calling the old Object every 2. Any ideas...... I have copied the code here to give you an idea....... function newGet() { // Get Data var recObj= new ajaxObject('somefile.php', displaysomeData); recObj.update(); //Re-Check every 2 seconds setTimeout('newGet()',2*1000); } function intitializeApp() { if(blahblahblah) { newGet(); } } window.onload=intitializeApp; OK, so now I want to run another function like newGet, but have the timeout set to a diff interval Quote Link to comment Share on other sites More sharing options...
mainewoods Posted April 29, 2007 Share Posted April 29, 2007 start it with your other one: function intitializeApp() { if(blahblahblah) { newGet(); someotherfunction(); } } --have it call itself at it's end: function someotherfunction(){ bla bla bla... setTimeout('someotherfunction()',2*5000); } --code works because setTimeout spawns a whole new thread and then execution continues with the code located after setTimeout. The code located after setTimeout does not wait for the interval specified in settimeout! be warned that if the ajax calls are made at the same time, an entended complete page lock may occur in ie. Quote Link to comment Share on other sites More sharing options...
colandy Posted April 30, 2007 Author Share Posted April 30, 2007 Yippee !!!!!!!!......Many thanks, thought this was something I'd tried b4 but obviously got something wrong last time. Works a treat now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.