SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with XMLHttpRequest and internet explorer

    I have a problem with internet explorer.when i request data from a xmlhttprequest ie return nothing and the others browser works correctly.

    the code is:
    Code:
    var receiveReq = getXMLHttpRequest();
    var xmldoc;
    	
    	function getXMLHttpRequest() {
    		var
    		 XHR = null,
    		 browserUtente = navigator.userAgent.toUpperCase();
    		 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
    		  XHR = new XMLHttpRequest();
    		 // browser Internet Explorer
    		 // è necessario filtrare la versione 4
    		 else if(
    		  window.ActiveXObject &&
    		  browserUtente.indexOf("MSIE 4") < 0
    		 ) {
    		  // la versione 6 di IE ha un nome differente
    		  // per il tipo di oggetto ActiveX
    		  if(browserUtente.indexOf("MSIE 5") < 0)
    		   XHR = new ActiveXObject("Msxml2.XMLHTTP");
    		  // le versioni 5 e 5.5 invece sfruttano lo stesso nome
    		  else
    		   XHR = new ActiveXObject("Microsoft.XMLHTTP");
    		 }
    
    		 return XHR;
    	}
    
    ....
    if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
         receiveReq.open('GET', "xmlGet.php?chat=1",true);
         receiveReq.onreadystatechange = function(){
         if (receiveReq.readyState == 4) {
    	xmldoc = receiveReq.responseXML;
    	if(serviceChat)chatReceive();
        }
        receiveReq.send(null);
       }			
    }
    
    ...
    function chatReceive(){
       var chat_div = document.getElementById('div_chat');
       var online_div = document.getElementById('utenti_online');	
       var message_nodes = xmldoc.getElementsByTagName('message'); 
       var n_messages = message_nodes.length;
    ...

    The problem is that in ie n_messages is always equals to 0 and the others browser no
    Why?
    Thsnk

  2. #2
    SitePoint Zealot XandroZ's Avatar
    Join Date
    May 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You use a server(php) script to supply the XMLResponse, you are passing data to the server with GET xmlGet.php?chat=1 and you have more options
    chat=1;chat=2....;you do not use a direct XML file;So we need to see the php file too.
    I don't see where you passing the chat variable.
    In the php file you have have to use " header (“Content-type: text/xml”); " and $_GET[“chat”].Without the php and how you pass chat is hard to tell.
    I write some code what I think you want.

    Code:
    <script language = “javascript”>
    var XHR = false;var xmldoc;var getoptions;
    if (window.XMLHttpRequest) {
    XHR= new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    XHR = new ActiveXObject(“Microsoft.XMLHTTP”);
    }
    
    function getXML(dataSource)// data source is your file
    {
    if(XHR) {
    
    XHR.open(“GET”, dataSource);
    XHR.onreadystatechange = function()
    {
    if (XHR.readyState == 4 &&
    XHR.status == 200) {
    var xmlDocument = XHR.responseXML;
    ar chat_div = document.getElementById('div_chat');
       var online_div = document.getElementById('utenti_online');	
       message_nodes = xmldoc.getElementsByTagName('message');
    // message must be the  root (first) element
    function list(); //use a loop to read elements
    }
    }
    function list(){
    function listOptions ()
    {
    var loopIndex;
    for (loopIndex = 0; loopIndex < options.length; loopIndex++ )
    ..............
    }
    
    XHR.send(null);
    }
    
    </script>

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I try to modify the code like your code but not works.
    The site where there is this problem is:
    http://www.nerto.it

    Try to run it in ff or opera and try to run it in ie.
    In ie the parts in ajax not works.
    PS: The chat is the frame in bottom-right .
    Thanks

  4. #4
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no error found? seems ok here, I am running ff.


Bookmarks

Posting Permissions

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