/***************调用方法************** 最后修改时间为 2010-10-15
var aj          =   new ajax();
aj.url          =   "test.php";
aj.c.id         =   888;
aj.method       =   "post";
aj.responsetype =   "text";
aj.exe(function(str){
 alert(str);
});
*/
function ajax(){
this.method        ="get";         //请求的类型get与post
this.responsetype  ="text";        //返回的类型text与xml
this.url           ="delete.php";  //请求的地址
this.c={};
var http_request = false;
this.exe = function(reValue){
     var temp_time="&"+new Date().getTime();
     var reTextResponse = function(){
        if (http_request.readyState == 4) {
        if (http_request.status == 200) {
        reValue(http_request.responseText);
        } else {alert("页面有异常0。");}
        }
     };
     var reXMLResponse = function(){
        if (http_request.readyState == 4){
        if (http_request.status == 200){
        reValue(http_request.responseXML);
        } else { alert("页面有异常1。");}
        }
     };
    if(window.XMLHttpRequest){
        http_request = new XMLHttpRequest();
        if(http_request.overrideMimeType){
        http_request.overrideMimeType("text/xml");
        }
     }else if(window.ActiveXObject){
        try{
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e){
        try{
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }catch (e){}
        }
     }
     if (!http_request){
        window.alert("创建XMLHttpRequest对象实例失败.");
        return false;
     }

    switch(this.method.toLowerCase()){
        case "get":
        http_request.open("GET", this.url+"?"+this.get_content()+temp_time, true);
        http_request.send(null);
        break;
        case "post":
        http_request.open("POST", this.url, true);
        http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        http_request.send(this.get_content()+temp_time);
        break;
        default:
        window.alert("http请求类别参数错误。");
        return false;
    }

     switch(this.responsetype.toLowerCase()){
        case "text":
        http_request.onreadystatechange = reTextResponse;
        break;
        case "xml":
        http_request.onreadystatechange = reXMLResponse;
        break;
        default:
        window.alert("参数错误。");
        return false;
     }
 };
    this.get_content=function(){
        var obj=this.c;
        var str="";
        if(typeof(obj)=="object"){
        for( var n in obj){
        str+="&"+n+"="+encodeURIComponent(obj[n]);
        }
        return str;
        }else{
        return obj;
        }
    };
}
