//////////////////////////////////
//Ajax类
//////////////////////////////////
function MyAjax(){
    this.method = "POST";
    this.url = "";
    this.parameter = "";
    this.sync = true;
    this.transfers = function(obj){return ;};
    this.waiting = function(){return ;};
    if(this.xmlhttp = this.createXmlhttp()){
        this.stateChange();
    }
}

MyAjax.prototype = {//创建xmlhttprequest
    msxml : ['Msxml2.XMLHTTP','Microsoft.XMLHTTP'],
    createXmlhttp : function(){
        if(window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
            if(xmlhttp.overrideMimeType){
                xmlhttp.overrideMimeType('text/plain');
            }
        }else if(window.ActiveXObject){
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e){}
            }
        }
        return xmlhttp;
    },
    send : function(){
        if(this.method == 'GET'){
            this.xmlhttp.open(this.method,this.url+'?'+this.parameter,this.sync);
            this.xmlhttp.send();
        }else{
            this.xmlhttp.open(this.method,this.url,this.sync);
            this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
            this.xmlhttp.send(this.parameter);
        }
    },
    stateChange : function(){
        var _self = this;
        _self.xmlhttp.onreadystatechange = function(){
            if(_self.xmlhttp.readyState == 4){
                if(_self.xmlhttp.status == 200){
                    _self.transfers(_self.xmlhttp.responseText);
                }
            }else{
                _self.waiting();
            }
        }
    }
}

posted on 2010-03-04 23:18  wl666lw  阅读(213)  评论(0编辑  收藏  举报