Ajax 手写JS

var httpRequest = false;
var mesdivs = null
function sendRequest(url, mesdiv) {
 
    mesdivs = mesdiv;
    httpRequest = false;
    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {

        }
    }
    else if (window.ActiveXObject) {

        try {

            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");

        }
        catch (e) {

            try {

                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

            }
            catch (e) {
            }
        }
    }

    if (!httpRequest) {

        window.alert("no");
    }

    if (mesdivs == "sendmes") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    alert(string);

                    window.parent.document.location.reload();

                }
            }
        }
    }
    if (mesdivs == "addit") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    alert(string);

                    location.reload();

                }
            }
        }
    }
    if (mesdivs == "addclick") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                }
            }
        }
    }
    if (mesdivs == "confirm") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    alert(string);

                    location.reload();

                }
            }
        }
    }
    if (mesdivs == "AddReply") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {               
                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    sendRequest("/DataAccess/getComments.aspx?id=" + parent.document.getElementById("Hidden1").value, "getComments");
                    alert(string);
                    SetWinHeight(document.getElementById("win"));
                }
            }
        }
    }
  
      if (mesdivs == "addFTopic") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("提交内容成功!");
                        location.href = "topic-father.aspx";
                    }
                    else if (string == "1") {
                        alert("提交内容失败");
                    }
                    else {
                        alert("提交内容失败");
                    }
                }
            }
        }
    }
    if (mesdivs == "addMTopic") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("提交内容成功!");
                        location.href = "topic-mother.aspx";
                    }
                    else if (string == "1") {
                        alert("提交内容失败");
                    }
                    else {
                        alert("提交内容失败");
                    }
                }
            }
        }
    }
    if (mesdivs == "addWTopic") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("提交内容成功!");
                        location.href = "topic_wedding.aspx";
                    }
                    else if (string == "1") {
                        alert("提交内容失败");
                    }
                    else {
                        alert("提交内容失败");
                    }
                }
            }
        }
    }
    if (mesdivs == "getComments") {
        httpRequest.onreadystatechange = function() {       
            if (httpRequest.readyState == 4) {               
                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    document.getElementById("DivContent").innerHTML = string;


                }
            }
        }
    }
    if (mesdivs == "getComments2") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    document.getElementById("DivContent").innerHTML = string;


                }
            }
        }
    }

    if (mesdivs == "viewCart2") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                alert(ttpRequest.status);
                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    document.getElementById("divs").innerHTML = string;


                }
            }
        }
    }
    if (mesdivs == "getCareobject") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    document.getElementById("info1").innerHTML = string;


                }
            }
        }
    }
    if (mesdivs == "getReminder") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    document.getElementById("info2").innerHTML = string;


                }
            }
        }
    }
    if (mesdivs == "getLogin") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {
                    alert(url);
                    var string = httpRequest.responseText;
                    alert(string);
                    document.getElementById("divproInfo").innerHTML = string;


                }
            }
        }
    }
    if (mesdivs == "addProCookie") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {              
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                }
            }
        }
    }
    if (mesdivs == "getCollData") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("您还没有登录!");
                        parent.hideWinLay();
                    }
                    else if (string == "1") {
                        alert("收藏成功!");
                        parent.hideWinLay();
                    }
                    else if (string == "2") {
                        alert("收藏失败!");
                        parent.hideWinLay();
                    }
                    else if (string == "99") {
                        alert("收藏失败!");
                        parent.hideWinLay();
                    }
                    else {
                        alert("您已经收藏该礼品!");
                        parent.hideWinLay();
                    }
                }
            }
        }
    }
    if (mesdivs == "getWishData") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("您还没有登录!");
                        parent.hideWinLay();
                    }
                    else if (string == "1") {
                        alert("添加愿望成功!");
                        parent.hideWinLay();
                    }
                    else if (string == "2") {
                        alert("添加愿望失败!");
                        parent.hideWinLay();
                    }
                    else if (string == "99") {
                        alert("添加愿望失败!");
                        parent.hideWinLay();
                    }
                    else {
                        alert("您已经将该礼品添加到我的愿望!");
                        parent.hideWinLay();
                    }
                }
            }
        }
    }
    if (mesdivs == "getproInfo") {

        httpRequest.onreadystatechange = function() {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;                   
                    document.getElementById("tab_Recom").innerHTML = string;
                }
            }
        }
    }
    if (mesdivs == "getHotPro") {

        httpRequest.onreadystatechange = function() {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;                  
                    document.getElementById("divhotpro").innerHTML = string;
                }
            }
        }
    }
  
    if (mesdivs == "BindMobile") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;

                    document.getElementById("HiddenField1").value = string;
                    St();


                }
            }
        }
    }
    if (mesdivs == "sendTel") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("您的用户名或手机错误!");
                    }
                    else if (string == "1") {
                        location.href = "getpass_2_mobile.aspx";
                    }
                    else if (string == "3") {
                        alert("验证码错误!");
                    }
                    else {
                        alert("发送失败,请联系客服!");
                    }
                }
            }
        }
    }
    if (mesdivs == "sendPayTel") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string == "0") {
                        location.href = "getPaypass_3.aspx";
                    }
                    else if (string == "1") {
                        location.href = "../reg/wrong.htm";
                    }
                    else {
                        location.href = "www.guanxin.com";
                    }
                }
            }
        }
    }
    if (mesdivs == "sendEmail") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;
                    if (string == "0") {
                        alert("您的邮箱或用户名错误!");
                    }
                    else if (string == "1") {
                        location.href = "getpass_2_email.aspx";
                    }
                    else if (string == "3") {
                        alert("验证码错误!");
                    }
                    else {
                        alert("发送失败,请联系客服!");
                    }
                }
            }
        }
    }
    if (mesdivs == "sendPayEmail") {

        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {

                if (httpRequest.status == 200) {

                    var string = httpRequest.responseText;
                    if (string == "0") {
                        location.href = "getPaypass_3.aspx";
                    }
                    else if (string == "1") {
                        location.href = "../reg/wrong.htm";
                    }
                    else {
                        location.href = "www.guanxin.com";
                    }
                }
            }
        }
    }
    if (mesdivs == "handledTel") {
        httpRequest.onreadystatechange = function() {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string != "0") {
                        location.href = "getpass_3.aspx?name=" + string;
                    }
                    else {
                        alert("error");
                    }
                }
            }
        }
    }
    if (mesdivs == "handledEmail") {
        httpRequest.onreadystatechange = function() {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string != "0") {
                        location.href = "getpass_3.aspx?name" + string;
                    }
                    else {
                        alert("error");
                    }
                }
            }
        }
    }
    if (mesdivs == "handledPay") {
        httpRequest.onreadystatechange = function() {
            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    var string = httpRequest.responseText;
                    if (string == "0") {
                        location.href = "../reg/right.htm";
                    }
                    else {
                        location.href = "../reg/wrong.htm";
                    }
                }
            }
        }
    } 
    else if (mesdivs == "th") {
        httpRequest.onreadystatechange = function() {

            if (httpRequest.readyState == 4) {
                if (httpRequest.status == 200) {
                    $("ListBox3").options.length = 0;

                    var string = httpRequest.responseText;
                    var str = new Array();
                    str = string.split("|");
                    for (d = 0; d < str.length; d++) {
                        var se = new Array();
                        se = str[d].split(",");

                        jsAddItemToSelect($("ListBox3"), se[1], se[0]);
                    }
                }
            }
        }

 

    }
    httpRequest.open('get', url, true);
    httpRequest.send(null);
}


function GetFirst(a) {

    if (a == "se") {
        //$("daZhongXiao").innerHTML=$("ListBox1").item.innerText;
        $("HiddenField1").value = $("ListBox1").value;
        sendRequest("/dataAccess/getsecondtype.aspx?name=" + $("ListBox1").value + "&type=" + a, a);
    }
    else if (a == "th") {//$("daZhongXiao").innerHTML=$("daZhongXiao").innerHTML+">>"+$("ListBox2").value;
        $("HiddenField2").value = $("ListBox2").value;
        sendRequest("/dataAccess/getsecondtype.aspx?name=" + $("ListBox2").value + "&type=" + a, a);
    }
    else {//$("daZhongXiao").innerHTML=$("daZhongXiao").innerHTML+">>"+$("ListBox3").value;
        $("HiddenField3").value = $("ListBox3").value;
    }
}
function $(a) {
    return document.getElementById(a);
}
function jsSelectIsExitItem(objSelect, objItemValue) {
    var isExit = false;
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].value == objItemValue) {
            isExit = true;
            break;
        }
    }
    return isExit;
}

function jsAddItemToSelect(objSelect, objItemText, objItemValue) {

    if (jsSelectIsExitItem(objSelect, objItemValue)) {

    }
    else {
        var varItem = new Option(objItemText, objItemValue);
        //      objSelect.options[objSelect.options.length] = varItem;
        objSelect.options.add(varItem);

    }
}

function jsRemoveItemFromSelect(objSelect, objItemValue) {
    if (jsSelectIsExitItem(objSelect, objItemValue)) {
        for (var i = 0; i < objSelect.options.length; i++) {
            if (objSelect.options[i].value == objItemValue) {
                objSelect.options.remove(i);
                break;
            }
        }

    }
    else {
    }
}

function jsUpdateItemToSelect(objSelect, objItemText, objItemValue) {
    if (jsSelectIsExitItem(objSelect, objItemValue)) {
        for (var i = 0; i < objSelect.options.length; i++) {
            if (objSelect.options[i].value == objItemValue) {
                objSelect.options[i].text = objItemText;
                break;
            }
        }
    }
    else {
    }
}
function jsSelectItemByValue(objSelect, objItemText) {
    var isExit = false;
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].text == objItemText) {
            objSelect.options[i].selected = true;
            isExit = true;
            break;
        }
    }
    if (isExit) {
    }
    else
    { }
}
 

posted on 2010-02-24 10:01  badyue  阅读(1543)  评论(0编辑  收藏  举报

导航