SirAndy Posted October 22, 2007 Share Posted October 22, 2007 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... Quote Link to comment Share on other sites More sharing options...
SirAndy Posted October 22, 2007 Author Share Posted October 22, 2007 although, I would much rather to be able to launch the load(time) function every 60 seconds... with the settimeout but I am not sure what I'm doing... Quote Link to comment Share on other sites More sharing options...
xenophobia Posted October 22, 2007 Share Posted October 22, 2007 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!!! } 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.