Jump to content

AJAX, Javascript and timeout question


colandy

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/48676-ajax-javascript-and-timeout-question/
Share on other sites

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.