【ajax登陆框实现弹出窗口】ajax登陆框实现弹出层登录效果

更新时间:2017-05-18    来源:窗口特效    手机版     字体:

【www.bbyears.com--窗口特效】

 代码如下

var xmlHttp;
function createXMLHttpRequest()
{
    try
    {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(sc)
        {
            xmlHttp = null;
        }
    }

    if( !xmlHttp && typeof XMLHttpRequest != "undefined" )
    {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}
function showDiv()
{
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
    var bgObj = document.getElementById("divbg");
    bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:1;";

    // 获得事件Event对象,用于兼容IE和FireFox
    function getEvent()
    {
        return window.event || arguments.callee.caller.arguments[0];
    }
    document.getElementById("popDiv").style.display="block";
    document.getElementById("divbg").style.display="block";
}

function closeDiv()
{
    document.getElementById("popDiv").style.display="none";
    document.getElementById("divbg").style.display="none";
}

function readPDF(FDF_ID)
{
    var url = "readpdf.aspx?login=false&id=" + FDF_ID + "&r=" + Math.random();
    start_Login(url);
}
function Subscribe()
{
    var url = "Subscribe.aspx?Subscribe=true&login=false&r=" + Math.random();
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleState_Subscribe;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function start_Login(url)
{
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleState_Login;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function handleState_Login()
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            var j = xmlHttp.responseText.parseJSON();
            if(j.islogin == "false")
            {
                alert(j.Reason);
                showDiv();
            }
            else
            {
                //debugger
                closeDiv();
                if(j.exitfile == "true")
                {
                    //alert(j.filepath);
                    top.location.href = "http://" + window.location.host + "/" +j.filepath;
                }
                else
                {
                    if(j.Reason == "")
                    {
                        alert(j.filepath);
                    }
                    else
                    {
                        alert(j.Reason);
                    }
                }
            }
        }
    }  
}

function handleState_Subscribe()
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            var j = xmlHttp.responseText.parseJSON();
            if(j.islogin == "false")
            {
                alert(j.Reason);
                showDiv();
            }
            else
            {
                alert(j.Reason);
                closeDiv();
            }
        }
    }  
}

function pop_Login()
{
    var UserName = document.getElementById("pop_username").value;
    if(UserName.length == 0)
    {
        alert("请输入用户名");
        return false;
    }
    var PassWord = document.getElementById("pop_password").value;
    if(PassWord.length == 0)
    {
        alert("请输入密码");
        return false;
    }
    if(UserName.length > 0 && PassWord.length > 0)
    {
        var url = "readpdf.aspx?Login=true&UserName=" + UserName + "&PassWord=" + PassWord + "&r=" + Math.random();
        start_Login(url);
    }
}

function Subscribe_Login()
{
    var UserName = document.getElementById("pop_username").value;
    if(UserName.length == 0)
    {
        alert("请输入用户名");
        return false;
    }
    var PassWord = document.getElementById("pop_password").value;
    if(PassWord.length == 0)
    {
        alert("请输入密码");
        return false;
    }
    if(UserName.length > 0 && PassWord.length > 0)
    {
        var url = "Subscribe.aspx?Subscribe=true&login=true&UserName=" + UserName + "&PassWord=" + PassWord + "&r=" + Math.random();
        createXMLHttpRequest();
        xmlHttp.onreadystatechange = handleState_Subscribe;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
}


调用 方法

 代码如下

javascript:showDiv();">登录就可以了

后面的aspx文件,你只要按正常的登录设置session值再返回1,0状态就好了。

本文来源:http://www.bbyears.com/wangyetexiao/32730.html

热门标签

更多>>

本类排行