在Internet Explorer中的AJAX响应SCRIPT标签中删除 [英] SCRIPT tag removed from AJAX response in Internet Explorer

查看:163
本文介绍了在Internet Explorer中的AJAX响应SCRIPT标签中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们目前的项目的一些code返回与AJAX和我们使用innerHTML来把这个code一个DIV里面。

In our current project some code is returned with AJAX and we use innerHTML to place this code inside a DIV.

现在,我们寻找这个DIV所有可用的脚本标签和EVAL()这些脚本标记的内容(增加了一些信息,以一个全球性的阵列等)

Now we search this DIV for all available script tags and EVAL() the contents of these script tags (adds some information to a global array, etc)

scriptTags = responseElement.getElementsByTagName("script");

for (i = 0; i < scriptTags.length; i++) {
            eval(scriptTags[i].text);
        }

这可以完美运行在Firefox和Chrome。不过,在IE scriptTags显示为空。经进一步调查似乎responseElement的innerHTML不包含任何SCRIPT标签(而在Firefox / Chrome浏览器,他们在那里!)

This works perfect in Firefox and Chrome. But in IE scriptTags appears to be empty. Upon further investigation it seems that the innerHTML of the responseElement doesn't contain any SCRIPT tags (while in Firefox / Chrome they're there!)

任何人都知道的原因和/或解决?

Anyone know the cause and/or work around?

顺便说一句,这是我怎么把网页上的Ajax响应:

By the way, this is how I put the AJAX response on the page:

this.proxy.innerHTML = o.responseText;
scriptTags = this.proxy.getElementsByTagName("script");

调试o.responseText显示响应里面的SCRIPT标签。导航到this.proxy元素上的页面显示 SCRIPT标签,但在IE不会出现在Firefox / Chrome浏览器。

Debugging o.responseText shows the SCRIPT tags inside the response. Navigating to this.proxy element on the page shows no SCRIPT tag in IE but does show up in Firefox / Chrome.

推荐答案

该问题得到了解决由脚本标记,都在德Ajax响应之前增加一个额外的节点元素。 (溶液/原因:<一href="http://allofetechnical.word$p$pss.com/2010/05/21/ies-innerhtml-method-with-script-and-style-tags/" rel="nofollow">http://allofetechnical.word$p$pss.com/2010/05/21/ies-innerhtml-method-with-script-and-style-tags/)

The problem was fixed by adding an additional node element before the SCRIPT tags that were in de AJAX response. (solution/cause: http://allofetechnical.wordpress.com/2010/05/21/ies-innerhtml-method-with-script-and-style-tags/)

在未来,我们应该改变我们的应用程序,使得HTML被发回的JSON。

In the future we should change our application so that the HTML is sent back as JSON.

这篇关于在Internet Explorer中的AJAX响应SCRIPT标签中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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