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 02-19-2008, 06:07 AM   PM User | #1
nikku
New Coder

 
Join Date: Feb 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
nikku is an unknown quantity at this point
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!!!
nikku is offline   Reply With Quote
Old 02-19-2008, 11:04 AM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
&
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
shyam is offline   Reply With Quote
Old 02-20-2008, 04:52 AM   PM User | #3
nikku
New Coder

 
Join Date: Feb 2008
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
nikku is an unknown quantity at this point
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!!!
nikku is offline   Reply With Quote
Old 02-20-2008, 09:55 PM   PM User | #4
Isaak
New to the CF scene

 
Join Date: Feb 2008
Location: In your computer
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Isaak is an unknown quantity at this point
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.
Isaak 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 08:32 AM.


Advertisement
Log in to turn off these ads.