XML ActiveXObject IE。对象不支持此操作
我正在尝试使用 xml 和 javascript。在 Firefox 中,使用 XMLHttpRequest 效果很好,但在 IE (6-8) 中我收到错误:
Object doesn't support this action
我正在使用以下函数:
function createRequestObject(){
var request;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
return request;
}
然后用以下方式调用它:
var xhttp = createRequestObject();
xhttp.open("GET","myfile.xml",false);
...
有什么想法吗?
I am trying to work with xml and javascript. In firefox it works great using XMLHttpRequest but in IE (6-8) I am getting the error:
Object doesn't support this action
I am using the following function:
function createRequestObject(){
var request;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
return request;
}
And then calling it with:
var xhttp = createRequestObject();
xhttp.open("GET","myfile.xml",false);
...
Any thoughts??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试为请求指定一个局部变量,
var request
(尽管它看起来不应该解决它)。我会使用这个 fn 来实现轻量级 XHR:
用法:
Try specifying a local variable for request,
var request
( although it doesn't look like it should solve it ).I would use this fn for light-weight XHR:
Usage:
我认为你需要在请求前面放一个
var
:IE经常有全局变量的问题。
I think you need to put a
var
in front of request:IE often has problems with global variables.