标签归档:Ajax

IE6下 Ajax 的一个很怪异的问题

废话不说,直接上代码.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax</title>
<script type="text/javascript">
(function(){
var ajax = function(){
var arrArguments = arguments[0];
//得到主要的参数
this.req = null;
this.url = arrArguments.url;
this.callback = arrArguments.success;
this.method = arrArguments.method?arrArguments.method:'get';
this.settimeout = arrArguments.settimeout?arrArguments.settimeout:30;
this.ajax.prototype.sendRequest();
}
ajax.prototype = {
//初始化
init:function(){
},
//创建对象
createRequestObject:function(){
if(window.XMLHttpRequest){ ? ? ? ? //Firefox Opera Safri Chrome
this.req = new window.XMLHttpRequest();
}else if(window.ActiveXObject){ ? //IE
this.req = new window.ActiveXObject("Microsoft.XMLHTTP");
}else{
throw new Error("无法创建交互对象,请重新尝试.");
return false;
}
//返回创建的Ajax对相
return this.req;
},
//发送请求
sendRequest:function(){
var req = this.createRequestObject();
if(req){
try{
req.onreadystatechange = function(){
var ready = req.readyState;
var data = null;
if(ready==4){
data = req.responseText;
this.callback(data); ?//回调函数
//this.req = null;
}
}
req.open(method,url,true);
req.send(null);
}catch(e){
throw new Error(e);
return false;
}
}
}
}
window.ajax = ajax;
})();
ajax({
url:'http://192.168.0.111:8000/demo/Ajax/aaa.txt',
settimeout:'30',
method:'get',
success:methodA
});
function methodA(data){
alert(data);
}
</script>
</head>
<body>
</body>
</html>

其中在这里
if(ready==4){
data = req.responseText;
this.callback(data); //回调函数
//this.req = null;
}
这个this在IE6下居然是 Window.而其他浏览器都是XMLHTTP对象!难道这个也是IE6的BUG?