• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

responseXML.documentElement returns null object

 
Praveen palukuri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Liu Zhixiang
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, working fine.
 
Arvind Gudiseva
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen palukuri: Appreciate if you could have posted your solution as well to fix this problem.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried IE 6, the same issue.

All the HTML page encodings are UTF-8.
Thanks for any help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic