
function RunAjax(xmlHttpUrl, method, sendData, successFun, failFun, waitFun) // 创建xmlhttpxmlHttpuest,ajax开始
{
    var xmlHttp; //定义变量，用来创建xmlhttpxmlHttpuest对象

    if (window.XMLHttpRequest) //非IE浏览器，用xmlhttpxmlHttpuest对象创建
    {
        xmlHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) //IE浏览器用activexobject对象创建
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
    }

    if (xmlHttp) //成功创建xmlhttpxmlHttpuest
    {
        xmlHttp.open(method, xmlHttpUrl, true); //与服务端建立连接(请求方式post或get，地址,true表示异步)
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readystate == 4) //请求状态为4表示成功
            {
                if (xmlHttp.status == 200) //http状态200表示OK
                {
                    successFun(xmlHttp.responseText); //所有状态成功，执行此函数，显示数据					
                }
                else //http返回状态失败
                {
                    failFun("失败");
                }
            }
            else //请求状态还没有成功，页面等待
            {
                waitFun("等待");
            }
        }
        if (method == "Get") {
            xmlHttp.send(null); //发送请求
        }
        else if (method == "Post") {
            xmlHttp.setrequestheader("content-length", sendData == null ? 0 : sendData.length);
            xmlHttp.setrequestheader("content-type", "application/x-www-form-urlencoded");
            xmlHttp.send(sendData); //发送请求
        }
    }
}
function SuccessFun(responseText) //接受服务端返回的数据，对其进行显示
    {
        alert(responseText);
    }

    function FailFun(responseText) //接受服务端返回的数据，对其进行显示
    {
        //alert(responseText);
    }

    function WaitFun(responseText) //接受服务端返回的数据，对其进行显示
    {
        //alert(responseText);
    }
    function PostData(url,sendData) {       
       
        RunAjax(url, "Post", sendData, SuccessFun, FailFun, WaitFun);
    }    