Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get responseXML to work in my AJAX?

Status
Not open for further replies.

deadpool42

Programmer
May 24, 2004
40
0
0
I've been using the responseText property in my AJAX, but I decided to switch over to sending XML and now it doesn't work.

This Javascript:
Code:
alert(agent.handler.responseXML.documentElement.getElementsByTagName('test')[0]);
says undefined, but if I remove the [0], it says object HTMLcollection.

responseXML and documentElement both seem to be defined, so I'm assuming the XML is right. Here's the PHP that generates it:

Code:
header('Content-type: text/xml'); 
echo '<?xml version="1.0" encoding="ISO-8859-1"?><test><![CDATA[this is the content]]></test>';
 
This thread may help as someone else was having the same problem thread1600-1280943

It seems there is a bug (in IE!) with the responseXML , you can either parse the returned text with JavaScritp or this link may help..


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
After much testing, I finally figured out the problem: documentElement is the root element, so in this case, as far as Javascript was concerned, there was no element named test. Surrounding it with another element makes it work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top