一段很简洁很棒的原生态javascript的Ajax代码

[代码] [JavaScript]代码

var Ajax={};
Ajax._xmlHttp = function(){ return new (window.ActiveXObject||window.XMLHttpRequest)("Microsoft.XMLHTTP");}
Ajax._AddEventToXHP = function(xhp,fun,isxml){
    xhp.onreadystatechange=function(){
        if(xhp.readyState==4&&xhp.status==200)
            fun(isxml?xhp.responseXML:xhp.responseText);
    }    
}
Ajax.get=function(url,fun,isxml,bool){
    var _xhp = this._xmlHttp();    
    this._AddEventToXHP(_xhp, fun || function(){} ,isxml);
    _xhp.open("GET",url,bool);
    _xhp.send(null);    
}
Ajax.post=function(url,data,fun,isxml,bool){    
    var _xhp = this._xmlHttp();    
    this._AddEventToXHP(_xhp, fun || function(){},isxml);
    _xhp.open("POST",url,bool);
    _xhp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    _xhp.send(data);
}

//demo get 操作
Ajax.get("sjolzy.ajax.html",function(v){
    alert(v)
});

Ajax.get("sjolzy.robots.txt",function(v){
    document.write(v)
});