Re: javascript to execute ajax function every 30 seconds
On Jul 9, 11:24 am, Peter <peter.schille. ..@gmail.comwro te:
setInterval(you rfunction,milli seconds);
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);
}
Re: javascript to execute ajax function every 30 seconds
In comp.lang.javas cript message <ab5db72a-bd6c-48ae-8ba2-5b01b0937cbb@34
g2000hsf.google groups.com>, Sat, 12 Jul 2008 10:20:32, Peter Michaux
<petermichaux@g mail.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.demo n.co.uk/- FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demo n.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demo n.co.uk/batfiles.htm- also batprogs.htm.
Comment