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 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts

    problem with my ajax

    hello everyone,

    I have a ajax code which is showing an error in ie.
    It is not able to read the xml file

    Code:
    	function loadxml(url)
    	{
    
    
    			req = false;
    
    		var moz = (typeof document.implementation != 'undefined') && (typeof
    					document.implementation.createDocument != 'undefined');
    
    		var ie = (typeof window.ActiveXObject != 'undefined');
    
    		if (moz){ xmlDoc = document.implementation.createDocument("", "", null) ;}
    
    
        // branch for native XMLHttpRequest object
        if(window.XMLHttpRequest && !(window.ActiveXObject)) {
        	try {
    			req = new XMLHttpRequest();
    			if(req.overrideMimeType){
    
    					req.overrideMimeType('text/xml');
    					}
    
            } catch(e) {
    			req = false;
            }
    
        // branch for IE/Windows ActiveX version
        } else if(window.ActiveXObject) {
           	try {
            	req = new ActiveXObject("Msxml2.XMLHTTP");
          	} catch(e) {
            	try {
              		req = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch(e) {
              		req = false;
            	}
    		}
        }
    
    	if(req){
    		req.open("GET", url, true);
    		req.onreadystatechange = stateChanged;
    		req.setRequestHeader("Content-Type","text/xml");
    		req.send(null);
    			}
        }
    function stateChanged()
    	{  
    
    		if (req.readyState==4 && req.status==0)
    			{
    			  xmlDoc=req.responseXML.documentElement;}		  
                  alert(xmlDoc);	//alert1	   
    	}
    My xml file is in the same directory as my above code.

    My xml file opens properly in ie,firefox,and microsoft word.

    The problem is alert1 gives me a null value.

    Any suggestions will be of great help.

    Thanks
    Cheers!!!

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    &
    Quote Originally Posted by nikku View Post
    Code:
    function stateChanged()
    	{  
    
    		if (req.readyState==4 && req.status==0)
    			{
    			  xmlDoc=req.responseXML.documentElement;}		  
                  alert(xmlDoc);	//alert1	   
    	}
    you should check for status 200 which is the OK status code for HTTP
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shyam View Post
    &
    you should check for status 200 which is the OK status code for HTTP
    Thanks shyam,

    My xml file is in the same directory as my script.

    I read that if you have a local xml file then the status should be 0 and if you are getting the file froma server then the status should be 200.

    Can you also suggest why this runs in mozilla and not on ie.

    Cheers!!!

  • #4
    New to the CF scene
    Join Date
    Feb 2008
    Location
    In your computer
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why don't you use a framework for AJAX such as xajax (AJAX-only framework) or jQuery (complete framework)? It will save you a lot of time and by reading the code will learn from your previous mistakes and even learn new tricks.


  •  

    Posting Permissions

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