我写的一个JS文件,内容如下:var initializing_request="正在初始化请求...";
var sending_request="正在发送请求...";
var processing_request="正在处理请求...";
var failed_request="请求发送失败...";function Ajax(responseType){
this.httpRequest=this.createXMLHttpRequest();
this.responseType=responseType;
this.responseHandler=null;
}Ajax.prototype.createXMLHttpRequest=function(){
var httpRequest=null; 

try{
//Firefox, Opera 8.0+, Safari,IE7,IE8
httpRequest=new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType("text/xml");
}
    }catch(e){
try{
//Internet Explorer 6.0+
httpRequest=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
//Internet Explorer 5.5+
httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("您的浏览器不支持AJAX!");
return null;
}
}
}
    
    return httpRequest;
}Ajax.prototype.processHandler=function(){
var readyState=this.httpRequest.readyState;

if(readyState==1){

}else if(readyState==2){

}else if(readyState==3){

}else if(readyState==4){
var status=this.httpRequest.status;
if(status==200){
var resposneType=this.responseType;
if(responseType="HTML"){
this.responseHandler(this.httpRequest.responseText);
}else if(responseType=="XML"){
this.responseHandler(this.httpRequest.responseXML);
}
}else{

}
}
}Ajax.prototype.get=function(targetURL,responseHandler){
var rand=Math.random();
if(targetURL.indexOf("?")>=0){
targetURL=targetURL+"&rand="+rand;
}else{
targetURL=targetURL+"?rand="+rand;
}
this.responseHandler=responseHandler;
this.httpRequest.onreadystatechange=this.processHandler;
if (window.XMLHttpRequest) {
this.httpRequest.open("GET",targetURL);
this.httpRequest.send(null);
} else {
this.httpRequest.open("GET",targetURL,true);
this.httpRequest.send();
}
}Ajax.prototype.post=function(targetURL,content,responseHandler){
var rand=Math.random();
if(targetURL.indexOf("?")>=0){
targetURL=targetURL+"&rand="+rand;
}else{
targetURL=targetURL+"?rand="+rand;
}
this.responseHandler=responseHandler;
this.httpRequest.onreadystatechange=this.processHandler();
this.httpRequest.open("POST",targetURL);
this.httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
this.httpRequest.send(content);
}
我在testAjax.html里面是这样写测试的。
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">
    var targetURL="";
    var ajax=new Ajax("HTML");
    ajax.get("index.jsp",handler);

   function handler(responseText){
       alert("Handler");
       alert(responseText);
   }
</script>可是在测试过程中出现:
var readyState=this.httpRequest.readyState;这行中的this.httpRequest is undefined为什么会出现这样的错误呢?