本帖最后由 aluzi 于 2010-03-14 15:12:53 编辑

解决方案 »

  1.   

    把var http = null;
    改成this.http = null;试一试
    还有onreadystatechange必须要用无参的函数
      

  2.   

    不行的。关键是“this”关键字很让人费解。
      

  3.   

    怎么不行??
    看看下面的代码function mysearch()
    {
        this.http = null;
        this.id = "id1";
    }
    mysearch.prototype=
    {
        search:function()
        {
            var sUrl = ".....";
            if( this.http == null )
                this.http = new ActiveXObject("Microsoft.XMLHTTP");
            else if( this.http.readyState != 4 )
                return false;
            alert(this.id);
            this.http.onreadystatechange = this.handleResult;
            this.http.open( "get", sUrl, true );
            this.http.setRequestHeader( "CACHE-CONTROL", "nocache" );
            this.http.send();
        },    handleResult:function()
        {alert(this === window)
        //do something
        }
    }var a = new mysearch();
    a.search();要让类里的作用域为类实例即this指向本身,得用new 关键字实例化
      

  4.   


    var http;
    改为:
    this.http = null;this.http.onreadystatechange = this.handleResult;
    改为:
    var self = this;
    this.http.onreadystatechange = function(){self.handleResult()};