alert(3)不输出,提示过程调用错误
代码如下:<script>
//创建ajax对象
var Ajax = function(){
    var xmlHttp;
}Ajax.prototype.createXMLHttpRequest = function() {
    // IE
    if (window.ActiveXObject) {
        this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
alert(1);
    } 
    // Mozilla
    else if (window.XMLHttpRequest) {
        this.xmlHttp = new XMLHttpRequest();
    }
}Ajax.prototype.send = function(url){   
    this.createXMLHttpRequest();   
alert(2);
    this.xmlHttp.open("post",url,true);   
alert(3);
    this.xmlHttp.onreadystatechange=handleStateChange; //指定响应的函数   
    this.xmlHttp.send(null);   //发送请求   
}   
//设置回调函数
Ajax.prototype.handleStateChange = function(resFunction) {
    if(this.xmlHttp.readyState == 4) {
        if(this.xmlHttp.status == 200) {
            resFunction();
        }
    }
}
</script>
<body>
<script>
var myReq = new  Ajax();
myReq.send();
</script>
</body>

解决方案 »

  1.   

    var myReq = new  Ajax(); 
    myReq.send("这个函数需要指定一个你请求的url"); 
      

  2.   

    你的send方法是带参数的,而你调用的时候是没有参数的,所以报错.另外,下面这句也有问题:
    this.xmlHttp.onreadystatechange=Ajax.prototype.handleStateChange;
      

  3.   

    是的  send()里面没有参数的
    在就是this.xmlHttp.open("post",url,true); 中的post应该改为GET吧。 
      

  4.   

    1. 调用send方法是url参数不能为空
    2. send方法要修改一下:Ajax.prototype.send = function(url) {
        // save 'this' object
        var that = this;    this.createXMLHttpRequest();    
        alert(2); 
        this.xmlHttp.open("post",url,true);    
        alert(3);     this.xmlHttp.onreadystatechange = function() {
            // make use of closure to save current context
            that.handleReadyState();
        };
        
        this.xmlHttp.send(null);   //发送请求
    };