Hi,
I'm stuck, but it's almost working!
From a html page, my javascript calls a server-side php script. The php reads a value from a server-side .txt file and passes it back as a javascript variable. This all works fine.
However, I want it to loop within a javascript function every 5 seconds. The function does other stuff, so looping within this function is essential (I've simplified it in the example below).
Any advice would be appreciated, I don't want to learn Ajax quite yet as my brain's already full with trying to learn php/javascript!
I've got the following in my .txt file:
This gets pulled into an array by my .php code:
Finally, I've got the following in my .html page, which calls the .php:
(Ignore the gap between count and err1 in this last example - the form is playing games..)
This prints the number '81' on my html page, and works fine for the 1st load. After this is doesn't go through the loop anymore so the number remains the same. I've tried many ways to get the php call into the loop but it won't work.
I need help in working out how to put the .php call INSIDE the looping function.
thanks,
Will
I'm stuck, but it's almost working!
From a html page, my javascript calls a server-side php script. The php reads a value from a server-side .txt file and passes it back as a javascript variable. This all works fine.
However, I want it to loop within a javascript function every 5 seconds. The function does other stuff, so looping within this function is essential (I've simplified it in the example below).
Any advice would be appreciated, I don't want to learn Ajax quite yet as my brain's already full with trying to learn php/javascript!
I've got the following in my .txt file:
Code:
graph_counter1 81
Code:
<?php
Header("content-type: application/x-javascript");
//read html param to get graph_number
$graph_number = $_GET["graph_request"];
//open datafile and create array of each line
$fp=fopen('C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\frame_realtime.txt',"r");
while(!feof($fp)) {
$line=fgets($fp);
list($key,$value) = split("[[:space:]]+",$line);
$array[$key] = $value;
}
fclose($fp);
//send output back to calling page
echo 'var random_number="'.$array[$graph_number] .'";';
?>
Code:
<html>
<head>
<script type="text/javascript" src="realtime_read_values.php?graph_request=graph_count er1"></script>
<script type="text/javascript">
function AddBar1()
{
document.write(random_number);
setTimeout('AddBar1()', 5000);
}
</script>
</head>
<body onload="AddBar1()">
</body>
</html>
This prints the number '81' on my html page, and works fine for the 1st load. After this is doesn't go through the loop anymore so the number remains the same. I've tried many ways to get the php call into the loop but it won't work.
I need help in working out how to put the .php call INSIDE the looping function.
thanks,
Will