ajax update problem
Posted: Wed Mar 14, 2007 12:07 pm
I am trying to retrieve temperature data from a txt file on the serve + update it every 3 seconds.
I do get the updates, but the value is the same even when I go and change the temperature value manually from the txt file.
What I mean is that, looks like ie chaches the temperature value or something.
can anybody help?
The Ninja Space Goat | Just use PHP bbcode tags when there's php in the html, otherwise, use the syntax drop-down menu (select HTML)
I do get the updates, but the value is the same even when I go and change the temperature value manually from the txt file.
What I mean is that, looks like ie chaches the temperature value or something.
can anybody help?
Code: Select all
<?
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Time</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", "outdoortemp.txt",true);
xmlHttp.setRequestHeader("Cache-control","no-chache");
xmlHttp.setRequestHeader("Pragma","no-chache");
xmlHttp.send(null);
}
function handleStateChange()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
//document.write(xmlHttp.responseText);
alert(xmlHttp.responseText);
//setInterval('document.write(xmlHttp.responseText)',3000);
}
}
}
</script>
</head>
<body>
<script type="text/javascript">
//startRequest();
//setInterval('startRequest()',3000);
//1000 milliseconds=1 sec
</script>
<form action="#">
<input type="button" value="Temperature" onclick="startRequest();"/>
</form>
</body>
</html>