Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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?

  • #2
    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
    The order should be

    open
    onreadystatechange
    send

    You could also be cached

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I discovered that I was setting headers incorrectly, what is the correct way?

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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?

  • #6
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if(request.status == 304) {
    request = cached;
    }

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

    Cheers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •