﻿
// JScript 文件
var WebUrl;
WebUrl="/VisCms_ServerProcess.ashx";
var Ajaxer = function(URL,callBackFunction,errorFunction,ProMethod,strPara,blTrans)
{
    
    if(ProMethod==null)
    {
        this.AjaxMethod = "GET";                            //默认传输方式 POST;
    }
    else
    {
        this.AjaxMethod=ProMethod;
    }
    
    this.SendObject = null;                                //传输的内容，默认null    
    if(strPara!=null)
    {
        this.SendObject=strPara;
    }
    this.ResponseType = "Text";                        //返回值类型 
    if(blTrans==null)
    {
        this.Async = true;                                        //异步方式
    }
    else
    {
        this.Async = false;                                        //不是异步方式
    }
    
    
    function createXMLHttp()
    {
        var xmlhttp;
        try
        {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (ex)
        {
            try
            {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (ex)
            {
                xmlhttp = new XMLHttpRequest();
            }
        }
        return xmlhttp;
    }
    
    var xmlHttp;    
     this.send =    function ()
    {
        xmlHttp = null;
        xmlHttp = createXMLHttp();
        if(xmlHttp == null)
        {
            alert("创建xmlHTTP失败！");
        }else
        {
            if((this.Async==false) && (ie==false)) 
            {
                xmlHttp.open(this.AjaxMethod,URL,this.Async);
                if(this.SendObject!=null)
                {
                    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                }
                xmlHttp.send(this.SendObject);                
                callBackFunction(xmlHttp.responseText);                
            }
            else
            {
                xmlHttp.onreadystatechange = this.SendBack;
                xmlHttp.open(this.AjaxMethod,URL,this.Async);
                if(this.SendObject!=null)
                {
                    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                }
                xmlHttp.send(this.SendObject);
            }
        }
    }
    
    this.SendBack = function (){
        
        if(xmlHttp.readyState == 4){
            if(xmlHttp.status == 200){
                
                var res;
                res = xmlHttp.responseText;
                callBackFunction(res);                
            }else{
                var error = eval(error + "=" + "{\"code\":\"" + xmlHttp.status + "\",\"message\":\"" + xmlHttp.statusText + "\"}" );
                errorFunction(error);
            }
        }
    }
    
}

 


