Hi there, I have a quick question.
This script is fairly simple. It works great in firefox, doesn't seem to work in IE. My document.getElementById('theTime').value gets set in firefox, but not in IE.
The php script returns a simple time string with the current server time, like March 10, 2005 11:15am, for example.
In firefox, the time updates every 5 seconds as I would expect.
In IE the time never changes and remains at the first value retrieved from the server. I'm returning no-cache headers from the php script.
Anyone have any ideas?
This script is fairly simple. It works great in firefox, doesn't seem to work in IE. My document.getElementById('theTime').value gets set in firefox, but not in IE.
The php script returns a simple time string with the current server time, like March 10, 2005 11:15am, for example.
In firefox, the time updates every 5 seconds as I would expect.
In IE the time never changes and remains at the first value retrieved from the server. I'm returning no-cache headers from the php script.
Anyone have any ideas?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head>
<title>XmlHttpRequest</title>
<script language="javascript" type="text/javascript">
var url = "echotime.php?param=";
var http = getHTTPObject();
function startAjax()
{
getTime();
setInterval('getTime();', 5000);
}
function handleHttpResponse()
{
if (http.readyState == 4)
{
if (http.status == 200)
{
document.getElementById('theTime').value = http.responseText;
}
else
{
alert("There was a problem retrieving the XML data:\n" + http.statusText);
}
}
}
function getTime()
{
http.onreadystatechange = handleHttpResponse;
http.open("GET", url, true);
http.send(null);
}
function getHTTPObject()
{
if (window.XMLHttpRequest)
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}
else if (window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
window.alert("ms.xmlhttp");
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
}
return xmlhttp;
}
</script>
</head>
<body onload="startAjax();">
<form action="post" ID="theForm">
<label for="time">time</label>
<input type="text" name="test" id="theTime" width="200px" size="200px" value="crap"/>
</form>
</body>
</html>