Jump to content

Functions


SirAndy

Recommended Posts

ok...this is probably a stupid question but..

 

I have two functions:

 

function load(t) {

  http.open("GET", "content/time.php", true);

  http.onreadystatechange=function() {

    if(http.readyState == 4) {

      document.getElementById('time').innerHTML = http.responseText;

    }

  }

  http.send(null);

}

 

and

 

function load(links) {

  http.open("GET", "content/links.php", true);

  http.onreadystatechange=function() {

    if(http.readyState == 4) {

      document.getElementById('body').innerHTML = http.responseText;

    }

  }

  http.send(null);

}

 

and if i put <a href="javascript:load(links)">links</a> or <a href="javascript:load(t)">time</a> it does what i want, i am wanting to know how to put them together so that, one click runs both functions...

Link to comment
Share on other sites

Solution for your first post is:

 

<a href="javascript: load(link); load(t)">Click me!</a>

 

For your seconds post, it really depends how you wan your function to be 'recursion'. You can do something like this:

 

function start_load(parameter_me)
{
    // do your function...
    var sec = 5;
    sec *= 1000;

    setTimeout("start_load('" + parameter_me + "')", sec);
}

 

So the above function will be run every 5 second. put in anything  you want inside to perform your task.

 

But from your code i read, you are trying to do something involved AJAX, so my wise suggestion is not to use timer, because the client connection will not guarantees all the task will be done in 5 seconds.

 

If second time of the function is called while the previous task is not completed, this will caused crash to your js.

 

What is suggest is put your recursion upon you get the result returned. Which mean in here:

if(http.readyState == 4)
{
    // Put your code here!!!
}

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.