Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-08-2009, 08:35 AM   PM User | #1
singedpiper
Regular Coder

 
Join Date: Jan 2005
Posts: 221
Thanks: 2
Thanked 0 Times in 0 Posts
singedpiper is an unknown quantity at this point
Question Code not updating in IE... Help?

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:

Code:
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?
singedpiper is offline   Reply With Quote
Old 03-08-2009, 03:46 PM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
The order should be

open
onreadystatechange
send

You could also be cached

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 03-08-2009, 05:57 PM   PM User | #3
singedpiper
Regular Coder

 
Join Date: Jan 2005
Posts: 221
Thanks: 2
Thanked 0 Times in 0 Posts
singedpiper is an unknown quantity at this point
Code:
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 is offline   Reply With Quote
Old 03-08-2009, 06:11 PM   PM User | #4
singedpiper
Regular Coder

 
Join Date: Jan 2005
Posts: 221
Thanks: 2
Thanked 0 Times in 0 Posts
singedpiper is an unknown quantity at this point
I discovered that I was setting headers incorrectly, what is the correct way?
singedpiper is offline   Reply With Quote
Old 03-08-2009, 10:54 PM   PM User | #5
singedpiper
Regular Coder

 
Join Date: Jan 2005
Posts: 221
Thanks: 2
Thanked 0 Times in 0 Posts
singedpiper is an unknown quantity at this point
Question

i'm trying some code from wikipedia, but although FF still runs beautifully, now IE6 gives an error on line 50 char 2

Code:
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?
singedpiper is offline   Reply With Quote
Old 04-24-2009, 03:23 AM   PM User | #6
Yipeng
New to the CF scene

 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Yipeng is an unknown quantity at this point
if(request.status == 304) {
request = cached;
}

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

Cheers.
Yipeng is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:17 PM.


Advertisement
Log in to turn off these ads.