﻿function ajax()
{
    var xmlHttp;
    
    this.createRequestXmlHttp=function()
    {
//        if(window.activeXObject)
//        {
//            xmlHttp=window.activeXObject("Microsoft.XMLHTTP");
//        }
//        else if(window.XMLHttpRequest)
//        {
//            xmlHttp=new XMLHttpRequest();
//        }
        if(window.ActiveXObject)
        {
            //xmlHttp=window.ActiveXObject("Microsoft.XMLHTTP");
            try {   
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");   
                } catch (e) {   
                    try {   
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
                    } catch (e) {}   
                }   
        }
        else if(window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        }
    }
    
    /****************************************************************
    pageUrl：请求的路径
    methodName：请求的方法名
    param：发送的参数
    method：指明是“GET”还是“POST”
    async：指明同步进行还是异步进行，true为异步进行
    ****************************************************************/
    this.callServerNoBack=function(pageUrl,methodName,param,method,async)
    {
        this.createRequestXmlHttp();
        //xmlHttp.onreadystatechange=this.handleRequest;
        if(method.toUpperCase()=="GET")
        {  
            xmlHttp.open("GET",pageUrl+"/"+methodName+"?"+param,async);
            xmlHttp.send(null);
        }
        else
        {
            xmlHttp.open("POST",pageUrl+"/"+methodName,async);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.send(param);
        }
    }
    
    /****************************************************************
    pageUrl：请求的路径
    methodName：请求的方法名
    param：发送的参数
    method：指明是“GET”还是“POST”
    async：指明同步进行还是异步进行，true为异步进行
    ****************************************************************/
    this.callServerAndBack=function(pageUrl,methodName,param,method,async)
    {
        this.createRequestXmlHttp();
        xmlHttp.onreadystatechange=this.handleRequest;
        if(method.toUpperCase()=="GET")
        {  
            xmlHttp.open("GET",pageUrl+"/"+methodName+"?"+param,async);
            xmlHttp.send(null);
        }
        else
        {
            xmlHttp.open("POST",pageUrl+"/"+methodName,async);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.send(param);
        }
    }
    
    this.handleRequest=function()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                document.getElementById("DIV_backInfo").innerHTML=xmlHttp.responseText;
            }
        }
    }
}
