aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes responseXML.documentElement returns null object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "responseXML.documentElement returns null object" Watch "responseXML.documentElement returns null object" New topic
Author

responseXML.documentElement returns null object

Praveen palukuri
Ranch Hand

Joined: Feb 10, 2005
Posts: 65
hi,
i am doing my first application using Ajax. I am strucked with one problem. If any one helps me in this, i am so thankful to them.

I am able to get xml doc using "xmlHttp.responseText". But when i try to execute this
var xmlDoc=xmlHttp.responseXML.documentElement;
Above statement returns null.
Do i need to install any plug-ins or else(But i heard that for Ajax no additional software is needed).

Here is my full code :
function getDetails(str)
{
xmlHttp = GetXmlHttpObject();
if(xmlHttp == null)
{
alert("Your browser does not support AJAX");
return;
}
var url = "Ajax_DOM.xml";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}

function stateChanged()
{
try
{
if (xmlHttp.readyState==4)
{
//alert(xmlHttp.responseText)
var xmlDoc=xmlHttp.responseXML.documentElement;
var objNodeList = xmlDoc.getElementsByTagName("wkt");
for (var i=0;i<objNodeList.length;i++)
{
var no = new Option();
no.text = objNodeList[i].childNodes[0].nodeValue;
no.value = objNodeList[i].attributes[0].value;
document.company.comptype[i+1]= no
}
}
}
catch(e)
{
//alert("Plese enter correct voicefilename : " + e);

}
}


function GetXmlHttpObject()
{
var xmlHttp = null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Please help me in this.

Regards,
Praveen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Firstly, please be sure to use UBB code tags when posting code. Please read this for more information.

Secondly, be sure that you are returning a response content type of "text/xml".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Liu Zhixiang
Ranch Hand

Joined: Aug 12, 2006
Posts: 32
I think the header(text/xml) isn't a key.
Because it is get the xml straight!
Are you sure the syntax and configuration of Ajax_DOM.xml is right!
Can I see the Ajax_DOM.xml?
Or please open the xml with IE or Firefox by yourself before!


I Think Therefore I Am
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Originally posted by Liu Zhixiang:
I think the header(text/xml) isn't a key.


You are incorrect. Most Ajax implementations will not parse the response text as XML unless the content type identifies the response as an XML document.
Praveen palukuri
Ranch Hand

Joined: Feb 10, 2005
Posts: 65
Thank you foryour response. Ajax_DOM is correct. I ran this in IE and its giving valid xml output.
I will check this header(text/xml).
Praveen palukuri
Ranch Hand

Joined: Feb 10, 2005
Posts: 65
Thank you, working fine.
Arvind Gudiseva
Greenhorn

Joined: Jan 25, 2006
Posts: 2
Praveen palukuri: Appreciate if you could have posted your solution as well to fix this problem.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
This post is over 3 years old, I doubt the poster remembers

REad this on debugging the error: http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html

Eric
Dave WangWang
Greenhorn

Joined: Feb 26, 2010
Posts: 2
For the following code

responseXML.documentElement return null.

I changed the chinese characters to 'Beijing', it worked.


It is a character coding issue.



From a proxy, I see the ajax response in XML that is correct. Save it and open it in IE 8, no error.
But alert the ajax response text: it could not show the chinese characters and responseXML.documentElement return null.

IF I change the cityName to Beijing (ANSI), it works.
I am using IE 8.

How to fix this issue? Thanks for help in advance.
Dave
Dave WangWang
Greenhorn

Joined: Feb 26, 2010
Posts: 2
I tried IE 6, the same issue.

All the HTML page encodings are UTF-8.
Thanks for any help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: responseXML.documentElement returns null object
 
Similar Threads
problem with sending # character through ajax
Resfresh page and getting values when option is selected
How to display value in combo box using AJAX
Ajax no response
Regading getElementById