Internet Explorer 8原型和XMLHttpRequest [英] Internet Explorer 8 prototypes and XMLHttpRequest

查看:154
本文介绍了Internet Explorer 8原型和XMLHttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这部分是一个变通方法的请求,部分是试图说明Internet Explorer的原型实现仍然有问题。

This is partially a request for a workaround, and partially an attempt to get the word out that Internet Explorer's prototype implementation is still faulty.

以下代码不在Internet Explorer上工作。

The following code does not work on Internet Explorer.

XMLHttpRequest.prototype.old = XMLHttpRequest.prototype.open;
var x = new XMLHttpRequest();
x.old("POST", "test", false);

对于IE 8 beta以及所有以前的版本,XMLHttpRequest.prototype属性从未存在于第一位。在IE8中,它确实存在,但您将收到无效的过程调用或参数错误。 Internet Explorer不喜欢装饰。

For IE 8 beta, and all previous versions, the XMLHttpRequest.prototype property never existed in the first place. In IE8, it does exist, but you'll get a "Invalid procedure call or argument" error. Internet Explorer doesn't like decoration.

有没有人知道解决方法?

Does anyone know of a workaround for this?

更新

有人指出我可以使用新的函数和构造函数覆盖整个XMLHttpRequest,然后创建一个包装器脚本ala XMLHttpRequest.js 。原型方法要短得多,所以我仍然希望将它用于非IE浏览器。

It has been pointed that I could override the entirety of XMLHttpRequest with a new function and constructor, and then create a wrapper script ala XMLHttpRequest.js. The prototype method is much shorter, so I would still prefer to use it for non-IE browsers.

推荐答案

问题似乎是IE 8识别XMLHttpRequest,但不是一个函数。 Active X对象似乎仍然有效。我没有测试window.XMLHtppRequest的存在,而是测试window.XMLHtppRequest的类型。似乎工作正常。

The problem seems to be that IE 8 recognizes XMLHttpRequest, but not as a function. Active X objects still seem to work. Instead of testing for the existance of window.XMLHtppRequest, I test for the typeof window.XMLHtppRequest. seems to work OK.

我按如下方式记录了我的获取请求:

I recoded my get request as follows:

FG.ajax.getxhr = function(){
var xhr;
if (typeof window.XMLHttpRequest === 'function') {
    xhr  = XMLHttpRequest();
}
else {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr; 

这篇关于Internet Explorer 8原型和XMLHttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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