对象在Internet Explorer 10(Windows 8)中不支持属性或方法'transformNode' [英] Object doesn't support property or method 'transformNode' in Internet Explorer 10 (Windows 8)
问题描述
我遇到了一些JavaScript问题,这些问题似乎只出现在Windows 8上的Internet Explorer 10中(IE 7、8和9都可以正常工作).我正在做的基本工作是从Web服务获取XML和XSL,然后使用Sys.Net.XMLDOM对象将它们转换为JavaScript以呈现在页面上.
I am having some JavaScript issues that seem to only occur in Internet Explorer 10 on Windows 8 (IE 7, 8, and 9 all work fine). The basic jist of what I am doing is getting XML and XSL from a web service and then transforming them in JavaScript to render on the page using the Sys.Net.XMLDOM object.
XMLDOM = Sys.Net.XMLDOM;
var xsl = // XSL gotten from somewhere else
var xmlString = // XML gotten from somewhere else as a string...
var xml = new XMLDOM(xmlString);
var content = xml.transformNode(xsl);
当我在IE 10中使用以上代码时,我得到:
When I use the above code in IE 10, I get:
对象不支持属性或方法"transformNode"
Object doesn't support property or method 'transformNode'
关于Internet Explorer 10为何要这样做的任何想法?
Any ideas on why Internet Explorer 10 is doing this?
编辑
我也尝试过这个:
xmldoc = new ActiveXObject("Msxml2.DOMDocument");
xmldoc.async = false;
xmldoc.load(xml);
xsldoc = new ActiveXObject("Msxml2.DOMDocument");
xsldoc.async = false;
xsldoc.load(xsl);
var content = xmldoc.transformNode(xsldoc);
在所有早期版本的IE中都可以使用,但是在IE 10中我得到:
Which works in all previous versions of IE, but in IE 10 I get:
引用未声明的名称空间前缀:"atom".
Reference to undeclared namespace prefix: 'atom'.
推荐答案
找到了答案: IE 10要求使用带有responseType设置为"msxml-document"的XMLHttpRequest.将代码切换到该代码后,所有功能都可以在所有浏览器中完美运行:
IE 10 requires using an XMLHttpRequest with the responseType set as "msxml-document". Once I switched the code over to that, everything works perfectly in all browsers:
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject("Microsoft.XMLHTTP"); // For IE 6
}
xhr.open("GET", url, false);
try { xhr.responseType = "msxml-document"; } catch (e) { };
xhr.send();
这篇关于对象在Internet Explorer 10(Windows 8)中不支持属性或方法'transformNode'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!