javascript - jQuery prop('outerHTML') undefined in IE -
i have javascript function gets answer ajax call, xml, , goes through reading information.
the point function runs fine in chrome not in ie, since in ie prop('outerhtml') gets undefined.
i have gone through several posts , tried several possible solutions no success.
the javascript function following one:
function visualizararchivoasync(tipoarchivo,contenedorarchivoid,id) { debugger; $.ajax({ url: '../file/' + tipoarchivo + '/' + contenedorarchivoid + '/see/' + id +'.do', type:'post', data:'', datatype: 'json', cache: false }).done(function(data) { if(!data.error) { debugger; var respuesta = data.data.respuesta; var jsonresp = json.parse(respuesta); var parser = new domparser(); var xmldoc = parser.parsefromstring(jsonresp,"text/xml"); var mensaje = ''; if (xmldoc) { mensaje = mensaje + '<div id="divxmlteu">'; $(xmldoc).find('anuncio').each(function(){ var procedimiento = $(this).find('procedimiento').text(); debugger; var plural = $(this).find('procedimiento').attr('plural'); if(plural == 's'){ procedimiento = 'anuncio de procedimientos ' + procedimiento; }else{ procedimiento = 'anuncio de procedimiento ' + procedimiento; } mensaje = mensaje + '<br/> <p id="texto-mensaje"> <strong>' + procedimiento + '</strong> </p> '; debugger; if(!($(this).find('notificado')===null || $(this).find('notificado')===undefined || $(this).find('notificado')==='undefined' || $(this).find('notificado').length == 0 )){ mensaje = mensaje + '<br/> <p> <strong> notificados </strong> </p> '; mensaje = mensaje + '<table id="tablanotificados"> ' + '<thead id="tablehead"> ' + '<tr style="display: block;width: 550px; text-align: left;"> <th style="width:58%;">nombre</th> <th style="width:15%;text-align: left;">tipo doc.</th> <th style="width:15%;">núm. doc.</th> </tr></thead> <tbody id="tablebody"> '; $(this).find('notificado').each(function(){ var notificado = $(this).text(); var id = $(this).attr('id'); var tipid = $(this).attr('tipid'); mensaje = mensaje + '<tr style="text-align: left;"><td style="width:58%;">' + notificado + '</td><td style="width:15%;">' + tipid + '</td> <td style="width:15%;">' + id + '</td></tr>'; }); mensaje = mensaje + ' </tbody> </table>' } if(!($(this).find('texto')===null ||$(this).find('texto').length == 0)){ debugger; var texto = $(this).find('texto').prop('outerhtml'); mensaje = mensaje + '<br/> <p> <strong> contenido </strong> </p> '; mensaje = mensaje + '<div id="divcontenidoteu" style="text-align: justify;">'; mensaje = mensaje + texto; mensaje = mensaje + ' <p>' + $(this).find('firmante').text() + ' </p> '; mensaje = mensaje + ' <p> en ' + $(this).find('lugar').text() + ' ' + $(this).find('fecha').text() + '</p> '; mensaje = mensaje + '</div>'; } }); mensaje = mensaje + '</div>'; $('body').append(mensaje); $("#divxmlteu").dialog({ autoopen: false, modal: true, resizable: false, width: '600px', buttons : { "aceptar" : function() { $(this).dialog("close"); $('#divxmlteu').remove(); } }, open : function(event, ui) { $(".ui-dialog-titlebar-close").hide(); } }); $("#divxmlteu").dialog("open"); } else{ alert('ha ocurrido un error en la visualización del xml.'); } } else {//hubo error en la llamada alert(data.error.mensaje); } }).fail(function(jqxhr, textstatus, errorthrown) { alert( textstatus); }); return false; } edit: xml under jsonresp is:
<?xml version="1.0" encoding="utf-16"?> <envio> <version>1.0.0</version> <anuncios> <remitente> <nodoremitente>nodo remitente</nodoremitente> </remitente> <anuncio> <emisor> <nodoemisor>nodo emisor</nodoemisor> </emisor> <metadatos> <id>16249</id> <formpub>e</formpub> <datospersonales>n</datospersonales> <lgt>s</lgt> <procedimiento>de prueba del servicio web de gestión de notificaciones</procedimiento> <notificados> <notificado>alvaro jimenez</notificado> </notificados> </metadatos> <contenido> <texto> <p> notificación de prueba </p> <p> notificación de prueba </p> <p> notificación de prueba </p> </texto> <piefirma> <lugar>madrid</lugar> <fecha>2015-02-16</fecha> <firmante>firmante de prueba</firmante> </piefirma> </contenido> </anuncio> </anuncios> the point under chrome of fireforx, texto returns
<texto> <p> notificación de prueba </p> <p> notificación de prueba </p> <p> notificación de prueba </p> </texto> which want (the html code within texto tag) in explorer undefined text.
i have seen textcontent property not want because not html code.
any ideas? in advance.
internet explorer not provide outerhtml property (nor innerhtml) nodes in xml document (although in ie 11 seems work). can use xmlserializer (in ie 9+) work around that:
var node = $(xml).find('texto')[0]; // dom node // try outerhtml. if not available, use xmlserializer var texto = node.outerhtml || new xmlserializer().serializetostring(node); you'll note texto string may xmlns attribute root node. don't think matter way use it.
Comments
Post a Comment