Run PHP from setTimeout
Posted: Tue Sep 09, 2003 12:57 am
Can someone explain why executing PHP code from a setTimeout loop does not run after the first call to the function. As an example, the following code will display a random number the first time it is called. But successive calls will not change the PHP output. I know that it is running because the javascript variable Cnt increments ever 1000 milliseconds.
I have many situations where I would like to use this technique. For instance, dynamically updating market quotes and displaying news feeds.
Any help would be most appreciated.
jcoppo
Code: Select all
<HTML><HEAD><TITLE>Test</TITLE>
<SCRIPT type=text/javascript>
var Cnt=0;
function showtime(){
timerID = setTimeout("showtime()",1000)
var OUT = document.getElementById('OUT');
var n = '<?php echo intval(rand(1,20)); ?>';
Cnt++;
OUT.innerHTML=n+' '+Cnt;
}
</SCRIPT>
</HEAD>
<BODY onLoad="showtime()">
<DIV id=OUT></DIV>
</BODY></HTML>Any help would be most appreciated.
jcoppo