Hi,
Can anyone find why this setTimeout() loop isn't working - I'm getting:
'data_to_send' is undefined
Any help much appreciated, thanks.
BTW, ajax.js contains my handling for creating the XMLHttpRequest, called createRequest().
Can anyone find why this setTimeout() loop isn't working - I'm getting:
'data_to_send' is undefined
Any help much appreciated, thanks.
BTW, ajax.js contains my handling for creating the XMLHttpRequest, called createRequest().
Code:
<html>
<head>
<script src="ajax.js" type="text/javascript"></script>
<script language="JavaScript">
function getData(data_to_send,zone_id)
{
var url = "realtime_read_values.php";
var req = create_request();
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
req.send(data_to_send);
req.onreadystatechange = function()
{
if(req.readyState == 4 && req.status == 200)
{
document.getElementById(zone_id).innerHTML = req.responseText;
//setTimeout("getData(window.data_to_send)", 3000); // this doesn't work
}
}
setTimeout("getData(data_to_send,zone_id)", 5000);
}
</script>
<body onload="getData('graph_request=graph_counter1','zone1'); getData('graph_request=graph_counter2','zone2'); getData('graph_request=graph_counter3','zone3');">
<div id="zone1">
waiting for data..
</div>
<div id="zone2">
waiting for data..
</div>
<div id="zone3">
waiting for data..
</div>
</body>
</html>