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
    New Coder
    Join Date
    Dec 2005
    Location
    Dallas, TX
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer Problems in IE (AJAX Code)

    Ok, so as you can tell, I'm having some problems with some AJAX code of mine. The code works fine in FF and Opera, but not at all in IE. Could someone possibly tell me why?

    Code:
    var xmlDoc;
    var chatContent = "";
    var timeout;
    
    function loadXML() {
    	/*@cc_on @*/
    	/*@if (@_jscript_version >= 5)
    		try {
    			xmlDoc = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try {
    				xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e2) {
    				xmlDoc = false;
    			}
    		}
    	@end @*/
    	if (!xmlDoc && typeof XMLHttpRequest != 'undefined') {
    		xmlDoc = new XMLHttpRequest();
    	}
    	
    	if(!xmlDoc) {
    		alert('Your browser cannot handle this script');
    		return;
    	}
    	
    	if(xmlDoc.overrideMimeType) {
    		xmlDoc.overrideMimeType('text/xml');
    	}
    	xmlDoc.onreadystatechange = function () {
    		if(xmlDoc.readyState == 4) {
    			if(xmlDoc.status == 200) {
    				var xmlContent = xmlDoc.responseXML;
    				
    				for(var x = 0; x < xmlContent.getElementsByTagName("broadcast").length; x++) {
    					var author = xmlContent.getElementsByTagName("broadcast")[x].getAttribute("poster");
    					var author_id = xmlContent.getElementsByTagName("broadcast")[x].getAttribute("posterid");
    					var emote = xmlContent.getElementsByTagName("broadcast")[x].getAttribute("emote");
    					var message = xmlContent.getElementsByTagName("broadcast")[x].firstChild.data;
    					if(emote == 0) {
    						chatContent += '[Broadcast]<a href="/profile.php?uid='+author_id+'">'+author+'</a> - '+message+'<br />';
    					} else {
    						chatContent += '[Broadcast]<a href="/profile.php?uid='+author_id+'">'+author+'</a> '+message+'<br />';
    					}
    				}
    				
    				for(var x = 0; x < xmlContent.getElementsByTagName("message").length; x++) {
    					var author = xmlContent.getElementsByTagName("message")[x].getAttribute("poster");
    					var author_id = xmlContent.getElementsByTagName("message")[x].getAttribute("posterid");
    					var emote = xmlContent.getElementsByTagName("message")[x].getAttribute("emote");
    					var message = xmlContent.getElementsByTagName("message")[x].firstChild.data;
    					if(emote == 0) {
    						chatContent += '<a href="/profile.php?uid='+author_id+'">'+author+'</a> - '+message+'<br />';
    					} else {
    						chatContent += '<a href="/profile.php?uid='+author_id+'">'+author+'</a> '+message+'<br />';
    					}
    				}
    				
    				document.getElementById("chatDiv").innerHTML = chatContent;
    				chatContent = "";
    				timeout = setTimeout('loadXML()', 5000);
    			} else {
    				document.getElementById("chatDiv").innerHTML = "There was an error with the chat script. Please report this to an admin.";
    			}
    		}
    	}
    	
    	xmlDoc.open('GET', 'http://somewhere.com/xml_file.php', true);
    	xmlDoc.send(null);;
    }
    Thanks!

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    What exactly are you experiencing?
    Helping to build a bigger box. - Adam Matthews

  • #3
    New Coder
    Join Date
    Dec 2005
    Location
    Dallas, TX
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Basscyst
    What exactly are you experiencing?
    Well, it's supposed to grab the XML from the page and display it in an iframe as chat, and in Firefox and Opera, it works, but it doesn't in IE. And I have no clue how to fix it, since my IE for some reason keeps changing it back whenever I try to enable script errors.

  • #4
    New Coder
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have had some problems with using AJAX in IE, as IE caches the returned document if the request is the same. The trick is either to set HTTP headers on the xml document for no cacheing (instructions below if you're using PHP), or (ugly and hackish) append a GET request with a random value. I don't know if this is the problem you're having though.

    PHP Code:
    <?php
    // Date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    // always modified
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");

    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0"false);

    // HTTP/1.0
    header("Pragma: no-cache");
    ?>

  • #5
    New Coder
    Join Date
    Dec 2005
    Location
    Dallas, TX
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, no good. If you'd like a link to the site in question, PM me and I'll give it to you. I would post it here, but I'm A: worried about spam, and B: worried about someone exploiting flaws in un-finished coding, so...

    Osiris

  • #6
    New Coder
    Join Date
    Dec 2005
    Location
    Dallas, TX
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alrighty, it's all good. I got it fixed... I ended up having to fork the code off to have the IE code use the Microsoft.XMLDOM object instead of the Microsoft.XMLHTTP object. A bit of a pain, but meh - it works. Thanks for the help, everyone!
    Owner - Osiris Incorporated

    PHP and MySQL pro, and always willing to help.


  •  

    Posting Permissions

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