【发布时间】:2009-02-27 11:40:46
【问题描述】:
我在使用 AJAX 时遇到了一个特别棘手的问题,它在 IE7 和 Firefox 中运行良好,但在 IE6 中却不行。
我有一个非常简单的本土 AJAX 框架,它要求我通过添加几个属性来扩展 XMLHttpRequest 对象(或者在 IE 的情况下为 XMLHttpRequest ActiveXObject)。相关部分代码如下:
//the following is the constructor for our ajax request object - which extends the standard object. It is used in the method below it
function FD_XMLHttpRequest() {
var xmlHttpReq = false;
if (window.XMLHttpRequest) { // Mozilla/Safari
xmlHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
//we now have the request object - extend it with things we might need to store with it
xmlHttpReq.onReturnFunc = null; //******ERROR IN IE6******
xmlHttpReq.targetDivId = null; //******ERROR IN IE6******
return xmlHttpReq;
}
//To use:
myXHReq = new FD_XMLHttpRequest();
myXHReq.onReturnFunc = someFunction;
myXHReq.targetDivId = "myDiv";
问题似乎是 FF 和 IE7 允许以这种方式扩展对象,但 IE6 不允许(它抱怨“对象不支持此属性或方法”)。我尝试过使用“原型”属性和“真实”继承的各种方法,但我无法完全理解 IE6 发生了什么
【问题讨论】:
标签: javascript ajax internet-explorer prototype