473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML HTTP GET does not seem to work in IE6 when used with setTimeout

I am trying to get the output of a php script to be displayed on a page
using the following (I have drastically simplified the PHP script and
have used MSXML2.XMLHTTP.4.0):

time.html:
<html>
<head>
<script type="text/javascript" language="javascript">
var xmlhttp;
function loadXMLDoc() {
xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.4.0");
}
if (xmlhttp!=null) {
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4)
if (xmlhttp.status==200) {
document.getElementById("refresher_div").innerHTML =
xmlhttp.responseText;
setTimeout("loadXMLDoc()", 1000);
}
};
xmlhttp.open("GET","time.php",true);
xmlhttp.send(null);
} else {
alert("Your browser does not support XMLHTTP.");
}
}
</script>
</head>

<body>
<center>
<div name="refresher_div" id="refresher_div">
Time will display here!!
</div>
</center>
</body>
</html>
<script language="javascript">
loadXMLDoc();
</script>
-----------------------------------8><-------------------------------------------
time.php:
<?php print date("r"); ?>
-----------------------------------8><-------------------------------------------
It all works fine in Firefox, but in IE6 and 5.0 the time does not
refresh on the page. Looking at the web server log, time.php does not
seem to load every second when it is running in IE6, and, using the
Script Debugger, the value of xmlhttp.responseText does not get
updated.

What am I doing wrong?

I've tried different versions of MS XMLHTTP, and have tried synchronous
GET statements, but no joy. I've tried debugging it with alert(
xmlhttp.responseText ), and it doesn't get updated. I've also tried
rearranging things, but the same fundamental problem remains.

Jul 23 '06 #1
2 2025


Robert S wrote:

time.php:
<?php print date("r"); ?>
-----------------------------------8><-------------------------------------------
IE is probably caching the page so make sure your PHP script sends the
right HTTP headers to indicate that it should not be cached respectively
expires immediately.

On the client-side if you are sure you want to force a new request then
it could help to use a unique query string each time e.g.
xmlhttp.open("GET","time.php?time=" + new Date().getTime(),true);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '06 #2
IE is probably caching the page so make sure your PHP script sends the
right HTTP headers to indicate that it should not be cached respectively
expires immediately.

On the client-side if you are sure you want to force a new request then
it could help to use a unique query string each time e.g.
xmlhttp.open("GET","time.php?time=" + new Date().getTime(),true);
I've done it this way - lifted from the php manual:

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
print date("r");
?>

The second suggestion also works.

If I run this on IE5.0, it starts skipping seconds after a while then
IE hangs. I assume that this is not fully supported.

Jul 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Malcolm | last post by:
I'm afraid I'm a newbie to javascript coding, so I hope this isn't too silly a question. Basically I'm trying to display a simple animation of a sequence of 24 hourly rain radar pictures...
2
by: Rob Nicholson | last post by:
How does setTimeout work? If the user moves the mouse or types some text into a form, does it reset the timer? Or does it start running when first triggered and simply timeout after that amount of...
6
by: Brent | last post by:
Is there any obvious reason why there's no delay in the execution of setting the id.style.display when this function gets called? function Hide(divId,timeout) { var id =...
10
by: Jarod | last post by:
Hey var service = this.WebServiceURL +"/SessionFun?sessionID="+ this.SessionID ; var xmlDoc=document.implementation.createDocument("", "", null); try {
4
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
10
by: samuelberthelot | last post by:
Hi, I have the following code that shows up a div with an animated gif inside, executes a cpu intensive function using setTimeout and then hide the div again: getEl('divWaiting').style.display...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
5
by: Gretsch | last post by:
Hi, Can someone help me with the command format please. I have a function (called fade) that was 3 parameters: the first 2 are colours therefore formatted #123456 and the 3rd is a number of...
1
by: sva0008 | last post by:
i have a auto suggest script that does not work in firefox , works great on IE. /******************************************************* AutoSuggest - a javascript automatic text input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.