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
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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.