...

View Full Version : Not sure why this won't update in IE.



herrin
03-10-2005, 07:17 PM
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?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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>

herrin
03-11-2005, 05:21 AM
I have added alerts and I know that it's doing a GET on the url, just not updating the .value in IE.

glenngv
03-11-2005, 06:49 AM
Does it go inside http.status 200 condition? Does it throw any error?

Try adding time in the url to avoid caching.

http.open("GET", url + new Date().getMilliseconds(), true);

herrin
03-11-2005, 07:55 AM
Hey, thanks for replying. Yes it does go into the status 200 block. I've verified with an alert in there.

Also, earlier I tried adding a url + math.random() and that wasn't effective either.

herrin
03-11-2005, 06:41 PM
In case anyone wonders, the solution dealt with the way MS's activex object works.


As for IE - If you add the following as the first line of getTime():



http = getHTTPObject();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum