jQuery XML parsing/manipulation IE8 error

删除回忆录丶 提交于 2019-12-06 15:21:24

There are 2 issues:

  1. From the docs:

    Query( html [, ownerDocument] )
    html: A string of HTML to create on the fly. Note that this parses HTML, not XML.

  2. IE, following the DOM-specification, does not accept the moving of nodes between documents.

This fixes both issues and works for me in IE too:

    //themes will be a jQuery-Object containing the documentElement
    var themes = $($.parseXML("<themes></themes>").getElementsByTagName('*')[0]);

    $.get('url/themes.xml', function(data, textStatus, jqXHR) {
        var xml = $($.parseXML(data));      
        themes.append(xml.children("themes").children('theme'));        
    }, 'text'
);

Try to serialize the fetch XML element in this way:

function xml2Str(xmlNode)
{
  try {
    // Gecko-based browsers, Safari, Opera.
    return (new XMLSerializer()).serializeToString(xmlNode);
  }
  catch (e) {
    try {
      // Internet Explorer.
      return xmlNode.xml;
    }
    catch (e)
    {//Strange Browser ??
     alert('Xmlserializer not supported');
    }
  }
  return false;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!