I'm trying to load fragments of XHTML markup using jQuery's $.fn.load function, but it raises an error trying to add the new markup into the DOM. I've narrowed this down to the XML declaration (<?xml... ?>) -- the view works if I return static text without the declaration. I don't understand why this would cause failure, or if the blame lies in jQuery, Firefox, or my code.
How should I insert XHTML fragments into the DOM using jQuery?
Using $.get does not work -- the callback receives a Document object, and when I try to insert it into the DOM, I receive the following error:
uncaught exception: Node cannot be inserted at the specified point in the hierarchy (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)
http://localhost:8000/static/1222832186/pixra/script/jquery-1.2.6.js
Line 257
This is my code:
$body = $("#div-to-fill");
$.get ("/testfile.xhtml", undefined, function (data)
{
console.debug ("data = %o", data); // data = Document
$body.children ().replaceWith (data); // error
}, 'xml');
A sample response: