I'm trying to write an AJAX application which periodically updated some data, here's the outline of my code, cut down to the important bits:
My problem is that on IE, the setTimeout event never fires, so update is called once when called by startup(), but then never again. On other browsers it works fine. I've tried replacing setTimeout(upda te, 500); with setTimeout('upd ate()', 500); but that didn't work either.
Can anyone suggest what I'm doing wrong?
Code:
...
var http = createRequestObject();
function createRequestObject() {
var ro;
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
ro = new ActiveXObject("Microsoft.XMLHTTP");
} else {
ro = new XMLHttpRequest();
}
return ro;
}
function startup() {
// Do Stuff
update();
}
function update() {
http.open('get', 'test.php');
http.onreadystatechange = updated;
http.send(null);
}
function updated() {
if (http.readyState == 4) {
// Do More Stuff
}
setTimeout(update, 500);
}
...
<body onload="startup();">
...
Can anyone suggest what I'm doing wrong?
Comment