一个封装的Ajax类

2019-09-14 07:21:34于海丽

        var msg = document.getElementsByName("message");
        for (var i=0;i<msg.length;i++){
            msg[i].parentNode.style.cssText = "position:absolute;bottom:" + (i*24) + "px;left:0px";
        }
    }
    this.showmsg = function (s) {
        v.style.display = "";
        v.all.Span1.innerHTML = s;
    }
}
function Ajax() {
    var x = new createXMLHttpRequest();
    this.Request = function (url,cmd,async,method,postString,title) {
        if (method!="post") method = "post"; else method = "get";
        if (async!=true) async = true; else async = false;
        if (typeof(postString)!="string") postString="";
        if (typeof(title)!="string") title="正在获取数据"; else title="正在获取" + title;
        var msgbox = new messageDiv(title);
        x.onreadystatechange = function ()
        {
            if (async) switch (x.readystate) {
            case 1:
                msgbox.showmsg("正在初始化连接...");
                return;
            case 2:
                msgbox.showmsg("正在发送数据...");
                return;
            case 3:
                msgbox.showmsg("正在接收数据...");
                return;
            case 4: