Weird Thoughts From Eric's Head

Tags - Categories : All | AJAX | BUSINESS | PERSONAL | PROGRAMMING | BOOK REVIEW

Ajax's responseXML Error

One thing that I see being asked more and more is why am I getting an error when I try to read the responseXML property. Well the main reason is normally the developer forgot to add the Content Type to set the document to XML. Other reasons is that the server has a problem with XML (I think I have seen this with Apache mainly.) As a result I wrote an article over on my site showing the error and how to correct it using the DOMParser. You can find the article here: http://www.pascarello.com/TestHTMLXMLfromServer.htm. The best solution is to set the Content Type and make sure the server is serving the dynamic XML documents correctly!

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages


Hi, Eric,

I used a sniffer program to trace the HTTP communication between my AJAX script and the ASP.NET web service webserver.  I found the webserver did respond

Content-Type: text/xml; charset=utf-8

in the header followed by the SOAP response message.  Would the extra "; charset=utf-8" have prevented the parser to load it automatically?  IE on XP with SP2 didn't have any problem loading the response message automatically.  I found I need to use your suggested approach to load the returned XML code explicitly on Mozilla-based browsers, e.g. Netscape 7.x and FireFox 1.5, though.

Timothy C.
With debugging people's code over time, I have seen that Mozilla and the others you mentioned are very strict on the XML document. If it is not 100% valid (one invalid character), it will not return the generated XML document from the server correctly. I would say run your generated XML through a validator and see if it is valid. Could be something as silly as an ampersand or less than/greater than sign in the text.
Eric


Add a comment

Title
Body
HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
Math Quiz 3 + 5 = (Helps stop blog spam)
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://radio.javaranch.com/pascarello/addTrackBack.action?entry=1130348276996