function Ajax()
{
    this.Async=null;//是否异步 默认(true)
    this.Method=null;//请求方式,(post|get) 默认(get)
    this.PostString=null;  //请求方式为post时,请求内容
    this.ParArray=null;  //参数数组
    this.PageUrl=null;//页面地址

    var NewUrl=null;
    
    this.GetXmlHttpRequest=function()
    {
        try
        {
            xmlHttp=new XMLHttpRequest();//firefox，opera8.0+，safari创建xmlhttp对象
        }
        catch(e)
        {
            //ie下创建xmlhttp对象
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                     xmlHttp=new ActiveXObject("Miscrosoft.XMLHTTP");
                }
                catch(e)
                {
                    return null;
                }
            }
        }
        return xmlHttp;
    }
    
    this.Parameters=function()
    {       
        if(this.Async==null)
        {
            this.Async=true;
        }
        if(this.Method==null||this.Method!="post")
        {
            this.Method="get";
        }
        if (typeof(this.PostString)!="string")
        {
            this.PostString="";
        }
                
        if(this.PageUrl!=null)
        {
            NewUrl=this.PageUrl+"?";
            if(this.ParArray!=null)
            {
                var arr=this.ParArray();
                for(i=0;i<arr.length;i++)
                {
                    if((i+1)==arr.length)
                    {
                        NewUrl+=arr[i][0]+"="+arr[i][1];
                    }
                    else
                    {
                        NewUrl+=arr[i][0]+"="+arr[i][1]+"&";
                    }
                }
            }
        }
    }

    this.OnReadyStateChange=function()
    {
        this.Parameters();//初始化参数
        var xmlHttp=this.GetXmlHttpRequest();
        if(!this.IsNull(xmlHttp))return; //是否支持AJAX
        
        var funloding=this.FunLodings;
        var funlodingsclose=this.FunLodingsClose;
        var funreturn=this.FunReturn;
        var funreturnxml=this.FunReturnXml;
        
        var async=this.Async;
        xmlHttp.onreadystatechange=function()
        {   
            if(async)
            {
                switch (xmlHttp.readyState) 
                { 
                    case 1: //正在初始化连接 
                        if(funloding!=null)funloding();
                        break;
                    case 2: //正在发送数据
                        
                        break;
                    case 3: //正在接收数据
                        
                        break;
                    case 4: //数据接收完成
                        if(xmlHttp.status==200)
                        {
                            if(funreturn!=null)funreturn(xmlHttp.responseText);
                            if(funreturnxml!=null)funreturnxml(xmlHttp.responseXML);
                            if(funlodingsclose!=null)funlodingsclose();//关闭提示
                        }
                        else
                        {
                            funreturn("请求失败," + xmlHttp.statustext + "(" + xmlHttp.status + ")");
                            if(funlodingsclose!=null)funlodingsclose();//关闭提示
                        }
                        break;
                }
            }
        }
        xmlHttp.open(this.Method,NewUrl,async);
        if(this.Method==null||this.Method!="post") //get提交
        {
            xmlHttp.send(null);
        }
        else //post提交
        {
            funloding();
            xmlHttp.setRequestHeader("content-length",this.PostString.length);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
            xmlHttp.send(this.PostString);
        }
        
        if (!async)
        {
            funloding();
            if(funreturn!=null)funreturn(xmlHttp.responseText);
            if(funreturnxml!=null)funreturnxml(xmlHttp.responseXML);
            if(funlodingsclose!=null)funlodingsclose();//关闭提示
        }
    }
    
    this.IsNull=function(xmlHttp)
    {
        if(xmlHttp==null)
        {
            alert("您的浏览器不支持ajax");
            return false;
        }
        return true;
    }
    
    this.FunLodings=null;  //初始化连接提示方法
    this.FunLodingsClose=null;  //数据接收完成关闭提示方法
    this.FunReturn=null;   //数据接收完成
    this.FunReturnXml=null;//数据接收完成，返回XML
}
