﻿function setAjax(url,arg,objId,backEvent){
    ajaxBase("get",url,arg,null,false,objId, backEvent);
}

//创建XMLHttpRequest对象
function createXmlHttp(){
    var xmlHttp=null;
    if(window.ActiveXObject){
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        if(window.XMLHttpRequest){
            xmlHttp = new XMLHttpRequest();
        }
    }
    return xmlHttp;
}


function ajaxBase(method, ajxUrl, request, postXml, isXml, resObjId, backEvent)
{
    var xmlHttp=createXmlHttp();
    xmlHttp.onreadystatechange=function(){ajaxCallBack(xmlHttp,resObjId,backEvent);};
    if(method.toUpperCase()=="GET"){
	    xmlHttp.open(method,ajxUrl+'?r='+Math.random()+'&'+request);
	    xmlHttp.send(null);
    }else{
       xmlHttp.open(method,ajxUrl+'?r='+Math.random()+'&'+request,true);
       if(!isXml){xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}
       xmlHttp.send(postXml);
    }
}

function ajaxCallBack(xmlHttp,resObjId,backEvent)
{
    if(xmlHttp.readyState==4)
    {
        try{clearWaitInfo();}catch(e){}
        if(xmlHttp.status==200)
        {
            if(resObjId!=null && document.getElementById(resObjId)!=null){
                document.getElementById(resObjId).innerHTML = xmlHttp.responseText;
            }
            
            if(backEvent!=null){
                var returnValue = xmlHttp.responseText;
                eval(backEvent);
            }
        }
    }
}

