Estoy tratando de cargar fragmentos de marcado XHTML usando la función $.fn.load
de jQuery, pero se genera un error al intentar agregar el nuevo marcado al DOM. He reducido esto a la declaración XML (<?xml...?>
): la vista funciona si devuelvo texto estático sin la declaración. No entiendo por qué esto podría causar un error, o si la culpa se encuentra en jQuery, Firefox o mi código.Cargando fragmentos XHTML sobre AJAX con jQuery
¿Cómo debo insertar fragmentos XHTML en el DOM usando jQuery?
Usando $ .get no funciona - la devolución de llamada recibe un objeto Document
, y cuando intento para insertarlo en el DOM, recibo el siguiente 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
Este es mi código:
$body = $("#div-to-fill");
$.get ("/testfile.xhtml", undefined, function (data)
{
console.debug ("data = %o", data); // data = Document
$body.children().replaceWith (data); // error
}, 'xml');
A de respuestas de ejemplo:
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml">
<form action="/gallery/image/edit-description/11529/" method="post">
<div>content here</div>
</form>
</div>