So, I’m a bit confused here.
I’m slowly progressing into ajax or HTML5 SSE, because I have list that, in the long run, I want to update without the user having to refresh. But, baby steps here, I’m starting with a simple function that should tell me when the file the list is reading from here, has changed, from another computer plugging in an entry.
CODE:
<script type='text/javascript'>
function CheckForChange(){
alert("<?echo (count($listArray)) . ' and ' . count(file($filename_noformat))?>");
}
setInterval("CheckForChange()", 7000);
</script>
listArray is the PHP variable that keeps the list seen on the page when the page refreshes, read line by line from a text file (I’m working on moving to a database, later)
Since PHP variables can only execute when the page is loaded, the PHP would only reflect what was in the text file when the PHP executed.
But with Javascript, and the setInterval function, shouldn’t it be able to execute the PHP to check what’s in the text file at the time that function is executed (every 7 seconds)? Because it’s not, and I don’t understand why not.
I try plugging in a 4th post to the list on my phone, and the phone’s alert changes to 4 and 4, but the computer still says 3 and 3. I want it to say 3 and 4.
Thanks
setInterval()executes local javascript in your page, not server-based PHP. If you want it to send something to your server without reloading the page, you would have to use an ajax call to actually send something to the server which could cause some PHP to execute.Hint – look at View/Source in your browser and see what is actually in your page. There’s no PHP in your page. The PHP runs on the server once when the page is created.