
function  Ajax(){
    //连接对象
    var _xmlHttp = false;
    //获取连接
    this.createXMLHttpRequest = function(){   
        try{   
            if (window.ActiveXObject) {
                _xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");                                         
            }else if (window.XMLHttpRequest) {
                _xmlHttp = new XMLHttpRequest();                                                   
            }
        }catch(e){   
             alert(e.name +" : " + e.message);   
        }   
     }   
    //回调函数
    this.backFunction = function(_backFunction){
         if(_xmlHttp.readyState == 4) {   
             if(_xmlHttp.status == 200) {   
                 _backFunction(_xmlHttp.responseText);//这里可以设置返回类型   
             }   
         }   
         _xmlHttp.onreadystatechange = null;
    }
    //post方法
    this.doPost = function(_url,_parameter,_backFunction){
        try{   
            _xmlHttp.open("POST",_url, false);
            _xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
            _xmlHttp.send(_parameter);    
        }catch(e){   
            alert(e.name +" : " + e.message);   
        }   
    }   
    //get方法
    this.doGet = function(_url,_parameter,_backFunction){   
        try{
            //防止重复提交方法一：增加一个随即数
            //var _random = Math.round(Math.random()*10000);
            //_xmlHttp.open("GET", (_url+"?random=" +_random +"&" + _parameter), false);
            _xmlHttp.open("GET", (_url+"?" + _parameter), false);
            //防止重复提交方法二
            _xmlHttp.setRequestHeader("If-Modified-Since","0");
            _xmlHttp.send(null);    
        }catch(e){   
            alert(e.name +" : " + e.message);   
        }   
    }
    //ajax调用接口                  url  参数         post or get  返回使用函数
    this.ajaxRequest = function(_url,_parameter,_method,_backFunction){   
        try{   
            this.createXMLHttpRequest();   
            if(_method.toLowerCase() == "post"){
                this.doPost(_url,_parameter,_backFunction);   
            }else{   
                this.doGet(_url,_parameter,_backFunction);     
            }   
            try{   
               _xmlHttp.onreadystatechange = this.backFunction(_backFunction);   
            }catch(err){   
            //不知道啥错误，反正好用
            }   
         }catch(e){
             alert(e.name +" : " + e.message);
         }
     }
}   