JavaScript and client side scripting.
Moderator: General Moderators
murlopaz
Forum Commoner
Posts: 60 Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA
Post
by murlopaz » 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?
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>
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)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 14, 2007 12:13 pm
The request headers you are sending aren't actually request headers, they are response headers (with bad values, I may add) that are supposed to be sent by the server.
murlopaz
Forum Commoner
Posts: 60 Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA
Post
by murlopaz » Wed Mar 14, 2007 12:18 pm
so what's the problem?
I am pulling the temperature file from a text file (only the temp value is in there).
Why isn't the new value shown when I manually update the temperature file?
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 14, 2007 12:30 pm
Caching?
murlopaz
Forum Commoner
Posts: 60 Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA
Post
by murlopaz » Wed Mar 14, 2007 12:31 pm
got it.
Thanks
murlopaz
Forum Commoner
Posts: 60 Joined: Wed Oct 11, 2006 5:02 pm
Location: Baltimore, MD, USA
Post
by murlopaz » Thu Mar 15, 2007 11:02 am
This works fine in firefox, but doesn't update the temp value in internet explorer. Does anybody have any ideas why?
Code: Select all
<!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", "KDMH.xml",true);
xmlHttp.send(null);
}
function handleStateChange()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
/*** temp is the name of the div container ***/
var temp_xml=xmlHttp.responseXML;
var temperature=temp_xml.getElementsByTagName("temp_f")[0];//.childNodes[0].nodeValue;
//document.getElementById("temp").innerHTML=temperature.childNodes[0].nodeValue;
alert(temperature.childNodes[0].nodeValue);
}
}
}
</script>
</head>
<body>
<table>
<tr>
<td id=temp>
<script type="text/javascript">
startRequest();
setInterval('startRequest()',3000);
//1000 milliseconds=1 sec, should be 15 minutes = 900000
</script>
</td>
</tr>
</table>
</body>
</html>