Friday, December 19, 2008

Parsing a Document into a DomDocument in JavaScript

XMLHttpRequest includes an attribute called responseXML besides responseText which should be populated when the returned data is XML. But actually often this doesn't work right because the headers are set right. Found this post by Darko in Google Groups about how to force parsing:

http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/762990f37ae218a3/6e0d948e1820bf24?pli=1

I called this in my "showResponse" function called by prototype.js' Ajax.Request onSuccess event. showResponse(originalRequest) receives the original XMLHttpRequest object and you need to call Darko's code using originalRequest.

However of course it didn't work for me-- in Firefox, the script runs forever. Turns out there was actually an error parsing the doc, but there's no way to tell what it is.

Time to add error output, which is defined nicely here:
http://www.faqts.com/knowledge_base/entry/versions/index.phtml?aid=15302

Haven't finished this yet :)

No comments:

Labels

Blog Archive

Contributors