...

View Full Version : Code not updating in IE... Help?



singedpiper
03-08-2009, 09:35 AM
i've got an ajax script that updates an image, by checking a dynamically modified text file (the reasoning behind this is complicated, but valid)... only thing is, my code doesn't work in IE 6.0.2900.2180 (the only IE i've tested in)
it simply refuses to update... but it works fine in FF

here's the axaj javascript file:



var req;

if(window.XMLHttpRequest){
//For Firefox, Safari, Opera
req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
//For IE 5
req = new ActiveXObject("Microsoft.XMLHTTP");
} else if(window.ActiveXObject){
//For IE 6+
req = new ActiveXObject("Msxml2.XMLHTTP");
}
else{
//Error for an old browser
alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
}





var lastResponse="";

function handleResponse(){
if(req.readyState == 4 && req.status == 200){
//returned text from the PHP script
var response = req.responseText;
if(response)
{
if (response != lastResponse)
{
document.getElementById("album_cover").src = response;
lastResponse = response;
}
}
else
{
lastResponse = "";
}
}
}

function refreshData()
{
req.open("GET","ajaxTarget.php", true);
req.send(null);
req.onreadystatechange = handleResponse;

setTimeout('refreshData()', 3000);
}

refreshData();



any ideas why i'm having no luck?

A1ien51
03-08-2009, 04:46 PM
The order should be

open
onreadystatechange
send

You could also be cached

Eric

singedpiper
03-08-2009, 06:57 PM
function refreshData()
{
var reqAddress = "ajaxTarget.php"+ "&dummy=" + new Date().getTime();
req.open("GET",reqAddress, true);

req.setHeader("Pragma", "no-cache");
req.setHeader("Cache-Control", "must-revalidate");
req.setHeader("Cache-Control", "no-cache");
req.setHeader("Cache-Control", "no-store");
req.setDateHeader("Expires", 0);

req.onreadystatechange = handleResponse;
req.send(null);

setTimeout('refreshData()', 3000);
}


this still fails to update... any other ideas?

singedpiper
03-08-2009, 07:11 PM
I discovered that I was setting headers incorrectly, what is the correct way?

singedpiper
03-08-2009, 11:54 PM
i'm trying some code from wikipedia, but although FF still runs beautifully, now IE6 gives an error on line 50 char 2




function refreshData()
{
req.open("GET","ajaxTarget.php", true);
req.send(null);

if(!req.getResponseHeader("Date"))
{ // <--this is line 50
var cached = req;
req = new XMLHttpRequest();
var ifModifiedSince = cached.getResponseHeader("Last-Modified");
ifModifiedSince = (ifModifiedSince) ?
ifModifiedSince : new Date(0); // January 1, 1970
req.open("GET", "ajaxTarget.php", false);
req.setRequestHeader("If-Modified-Since", ifModifiedSince);
req.send("");
if(req.status == 304) {
req = cached;
}
}



req.onreadystatechange = handleResponse;

setTimeout('refreshData()', 3000);
}





any ideas?

Yipeng
04-24-2009, 04:23 AM
if(request.status == 304) {
request = cached;
}

This status code is not valid for IE. Remove it and your problem will go away.

Cheers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum