ajax登陸框實現彈出層登入效果

來源:互聯網
上載者:User
 代碼如下 複製代碼

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);
    }
}


調用 方法

 代碼如下 複製代碼

<a href="javascript:showDiv();">登入</>就可以了

後面的aspx檔案,你只要按正常的登入設定session值再返回1,0狀態就好了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.