[Javascript] Re: XMLHTTP send and receive stumper

Ryan Cannon ryan at ryancannon.com
Wed Nov 9 12:36:52 CST 2005


For those who followed this thread, and I guess for posterity, and  
archives here was the answer I found to this problem:

xmlhttp.responseXML.firstChild is not a document node (which we are  
used to working with), but a document type node. The differences were  
a little too subtle for me to wrap my head around quickly, but you  
can test this by doing

alert(xmlhttp.responseXML.firstChild.nodeType);

It returns 10 instead of 9. This confusion is compounded by the fact  
that

alert(xmlhttp.responseXML.firstChild.nodeName);

returns "html", leading me to believe I was accessing the document  
root element, but this is actually because that what is declared by <! 
DOCTYPE html ...> in the file I requested.

The correct way to access the document node (hence gaining access to  
(document object functions) is

xmlhttp.responseXML.documentElement

All this confusion was cleared up straight from the source, the DOM  
Level 2 Core rec at the W3C[1], with a little help from.

     [1] http://www.w3.org/TR/DOM-Level-2-Core/core.html

Cheers,
-- 
Ryan Cannon

Wordslinger, Webwright
http://RyanCannon.com



On Nov 8, 2005, at 8:42 AM, Ryan Cannon wrote:

> Greetings,
>
> I'm attempting to use XML HTTP to send and receive XML data, and  
> then append the results to an XHTML page. Essentially I want to use  
> the following class (or similar):
>
> function Feed(name,url) {
>     this.name=name;
>     this.url=url;
>     this.status=0;
>     this.xml=null;
>     this.html=null;
>     this.load=function () {
>         loading=true;
>         loadXMLDoc(this.url,"GET",null);
>         this.status=1;
>     }
> }
>
> Feed.load() will download the appropriate url, and save it's  
> responseText in Feed.xml. the xmlhttp object will be dumped and re- 
> initialized, sending Feed.xml as a post variable to my XSLT  
> processor, which translates the XML into XHTML. This resultXML will  
> be stored in Feed.html, and later appended to the page.
>
> Everything seemed to be going swimmingly, until I try to append the  
> result. body.innerHTML+=xmlhttp.responseText works fine, but  
> body.appendChild(xmlhttp.responseXML) causes the following error in  
> Firefox:
>
> Error: [Exception... "Node cannot be inserted at the specified  
> point in the hierarchy"  code: "3" nsresult: "0x80530003  
> (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)" ...]
>
> I obviously don't want to use innerHTML since everything I'm doing  
> is in XML, but I haven't been able to find a good way to debug this  
> error. Also, there's some other browser-compatibility errors, so if  
> anyone could point to a good tutorial on sending XML and processing  
> an XML response with javascript, I'd appreciate it.
>
> Cheers,
> -- 
> Ryan Cannon
>
> Wordslinger, Webwright
> http://RyanCannon.com
>
>
>
>




More information about the Javascript mailing list