By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

javascript to execute ajax function every 30 seconds

P: n/a
How do you enable javascript to execute a given function every X
seconds, which is not dependant on any user input?

-Inet
Jul 9 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
setInterval(yourfunction,milliseconds);
Jul 9 '08 #2

P: n/a
On Jul 9, 11:24 am, Peter <peter.schille...@gmail.comwrote:
setInterval(yourfunction,milliseconds);
Please quote the message to which you are replying or state enough so
your message is sufficient to explain the context of your response.

----

Using setInterval to execute a given function every x seconds can be
dangerous. If the function's execution takes longer than x seconds
than the executions of the function "stack up" and dominate the system
because they are always executing.

I prefer to use setTimeout so that there is a specified period of time
between the end of the function's execution and the beginning of its
next execution.

function foo() {
// do stuff
// ...

// make a delayed recursive call to foo
setTimeout(foo, 3000);
}

Peter
Jul 12 '08 #3

P: n/a
In comp.lang.javascript message <ab5db72a-bd6c-48ae-8ba2-5b01b0937cbb@34
g2000hsf.googlegroups.com>, Sat, 12 Jul 2008 10:20:32, Peter Michaux
<pe**********@gmail.composted:
>
I prefer to use setTimeout so that there is a specified period of time
between the end of the function's execution and the beginning of its
next execution.

function foo() {
// do stuff
// ...

// make a delayed recursive call to foo
setTimeout(foo, 3000);
}
And one can call new Date() within function foo and from it calculate
a suitably-varied delay to replace the fixed 3000.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm- also batprogs.htm.
Jul 12 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.