JavaScript:XMLSerializer.serializeToString()的替换? [英] JavaScript: Replacement for XMLSerializer.serializeToString()?

查看:1936
本文介绍了JavaScript:XMLSerializer.serializeToString()的替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Seam框架和RichFaces AJAX库开发一个网站(这些对于手头的问题并不是那么重要 - 只是一些背景)。

I'm developing a website using the Seam framework and the RichFaces AJAX library (these isn't really all that important to the problem at hand - just some background).

然而,我似乎在RichFaces中发现了一个错误,在某些情况下,它会导致基于AJAX的更新在IE8中失败(有关详细信息,请参阅此处: http://community.jboss.org/message/585737

I seem to have uncovered a bug, however, in RichFaces which, in certain instances, will cause AJAX-based updating to fail in IE8 (see here for more info: http://community.jboss.org/message/585737).

以下是发生异常的代码:

The following is the code where the exception is occurring:

   var anchor = oldnode.parentNode;

   if(!window.opera 
       && !A4J.AJAX.isWebkitBreakingAmps() 
       && oldnode.outerHTML 
       && !oldnode.tagName.match( /(tbody|thead|tfoot|tr|th|td)/i ) ) {
         LOG.debug("Replace content of node by outerHTML()");
         if (!Sarissa._SARISSA_IS_IE || oldnode.tagName.toLowerCase()!="table") {
         try {
           oldnode.innerHTML = "";
         } catch(e){    
           LOG.error("Error to clear node content by innerHTML "+e.message);
           Sarissa.clearChildNodes(oldnode);
         }
       }
           oldnode.outerHTML = new XMLSerializer().serializeToString(newnode);
   }

最后一行(带有XMLSerializer的行)是发生异常的地方IE浏览器。我想知道是否有人知道我可以在那里使用的任何替换方法/库/等(仅在IE上很好)。谢谢。

The last line (the one with XMLSerializer) is where the exception is occurring in IE. I was wondering if anyone knows of any replacement method / library / etc I could use there (only on IE is fine). Thanks.

编辑:在做了一些进一步的研究之后,似乎异常不是由XMLSerializer没有被定义引起的,而是在我尝试的时候似乎发生了将XMLSerializer的输出分配给oldnode的outerHTML属性。

After doing some further research, it seems that the exception isn't being caused by XMLSerializer not being defined, rather it seems to happen when I try to assign the output from XMLSerializer to the outerHTML property of the oldnode.

这很奇怪,因为它可以工作很多次但只在几个场景中失败(这块框架似乎相当重要。)

This is strange because it works most times but fails in only a couple of scenarios (this piece of the framework seems to be rather important).

任何人都可以想到XMLSerializer输出的时间(从调试器显示的内容看起来非常有效) HTML)对元素的outerHTML属性不可分配

Can anyone think of any reason as to when the output from XMLSerializer (which, from the what the debugger shows, look to be quite valid HTML) is nonassignable to the outerHTML property of an element?

最奇怪的是,如果我要克隆元素(使用 cloneNode(true))然后设置outerHTML,它似乎工作。

The strangest thing is, if I were to clone the element (using cloneNode(true)) and then set the outerHTML, it seems to work.

推荐答案

<我已经发现了原因(前一段时间)。事实证明,IE半插入HTML验证(它会忽略一些错误但忽略其他错误)。它抛出一些未知错误或类似的东西几乎完全没用,因为它没有说明出了什么问题 - 只是出了点问题。

I've since discovered the reason (a while ago actually). It turns out that IE semi-validates (it'll balk at some errors but ignore others) inserted HTML. It was throwing some 'unknown error' or something similar which was pretty much completely useless since it gave no indication as to what went wrong - just that something went wrong.

In我的情况,这是因为< li />与父母一起插入。如果您遇到类似问题,可能需要确保不要过于聪明地使用HTML。

In my case, it was because an <li /> was being inserted with a parent . If you're having similar issues, you may want to make sure you're not trying to be too clever with your HTML.

这篇关于JavaScript:XMLSerializer.serializeToString()的替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆