• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

responseXML.documentElement returns null object

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, working fine.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Praveen palukuri: Appreciate if you could have posted your solution as well to fix this problem.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried IE 6, the same issue.

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