博客园 首页 联系 订阅 管理

/**........................................................................................
ajax异步调用的原理:
1.获得XMLHttpRequest对象
2.注册回调函数
3.设置连接信息
4.发送数据,开始和服务器端进行交互
5.接收响应数据
................................................................................................*/
var XMLHttpReq;
function getXMLHttpRequst(){
    if(window.XMLHttpRequest){
        XMLHttpReq = new XMLHttpRequest();
        //针对某些特定版本的mozillar浏览器的bug进行修正
        if(XMLHttpReq.overrideMineType){
            XMLHttpReq.overrideMineType("text/xml");
        }
    }else if(window.ActiveXObject){
        //针对IE6,IE5.5,IE5,两个可以创建XMLHttpRequest对象的控件名称,保存啊js的数组里面
        var activexName = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
        for(var i=0;i<activexName.length;i++){
            try{
                XMLHttpReq = new ActiveXObject(activexName[i]);
                break;
            }catch(e){}
        }
    }if(!XMLHttpReq){
        window.alert("XMLHttpRequest对象创建失败!");
    }else{
        return XMLHttpReq;
    }
}
function login(){
    var userName = document.getElementById("userName").value;
    var userPwd = document.getElementById("userPwd").value;
    XMLHttpReq = getXMLHttpRequst();
    XMLHttpReq.onreadystatechange = callback;
    XMLHttpReq.open("GET","login.aspx?userName="+userName+"&userPwd="+userPwd,true);
    XMLHttpReq.send(null);
    //XMLHttpReq.open("POST","admin/login.aspx",true);
    //XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    //XMLHttpReq.send("userName="+userName+"&userPwd="+userPwd);
}
function callback(){
    if(XMLHttpReq.readyState == 4){
        if(XMLHttpReq.status == 200){
            var responseText = XMLHttpReq.responseText;
            if(responseText == "yes"){
                location.href = "main.html";
            }else if(responseText == "noAdmin"){
                alert("你不是管理员!");
            }else{
                alert("用户名或密码不正确!");
            }
        }
    }
}

 

 

      if (admin == null)
                {
                    Response.Write("no");
                }
                else if (!(admin.Proxy.ProxyID == 0 && admin.IsAdmin == 0 && admin.IsProxyBusiness == 0))
                {
                    Response.Write("noAdmin");
                }
                else
                {
                    Enterprise.Utility.Common.SetSession("admin", admin);
                    Enterprise.Utility.Common.SetSession("sysAdmin", sysAdmin);
                    Response.Write("yes");
                }

posted on 2011-11-25 17:24  $蔷  阅读(1191)  评论(0编辑  收藏  举报