Show logout button after login without refresh

时间:2016-11-09 06:54:34

标签: jquery laravel-5

I need to show logout button after login without page refresh. So far I am thinking of jquery's .show() and .hide() on success in ajax. But the problem is, the logout button is in another page, how to achieved this?

 @if(Auth::check())
    <a href="{{ url('/logout') }}" class="btn-logout" id="logged">Logout</a>
 @endif

in ajax success

 success: function(data) { 
     console.log(data);
     $("#logged").show();
     //var logg = ("#logged");
     var logg= parent.document.getElementById('logged'); 
                alert(logg); 

     console.log(logg)//null
     ......

I need to show logout button immediately after login The login is inside modal and the id="logged" is int the main template

My login in modal

$("#login-form").on('submit', function(e) {
        e.preventDefault();
        console.log($(this).serialize());
        var datas = $(this).serialize();
        if($("#login-form #email").hasClass('has-error')) {
                $('#login-form #email').removeClass('has-error');
        }
        if($("#login-form #password").hasClass('has-error')) {
                $('#login-form #password').removeClass('has-error');
        }
        var green = $("#login-form .green")
        $.ajax({
            url: 'partA/user/login',
            data: datas,
            type: 'post',
            success: function(data) {
                var ht = window.opener.getElementById("logged");
                alert(ht);
                if (!data.errors) {
                    $("#static").modal('hide');
                    $("#logged").show();
                    toastr.info('You are now allowed to perform such operation');
                    startSessionTimer();
                    test = true;
                    $("#login").hide();
                } else {
                    $("#allowed").addClass('hide');
                    $("#notallowed").removeClass('hide');
                }
                console.log(data);
            },
            error: function(data) {
            }
        }).done(function(data) {
            if(!data.errors){
                var jeopardy_frame = $('iframe#jeopardy');
                var rotator_frame = $('iframe#rotator');
                jeopardy_frame[0].contentWindow.jSetRoles(data.roles);
                rotator_frame[0].contentWindow.jSetRoles(data.roles);
            }
        });
    });

1 个答案:

答案 0 :(得分:0)

  • 您需要添加该注销码(小心)默认隐藏并在成功登录时显示。

如果您不需要刷新,则只需添加代码即可实现此目的。

  • 其他方式是合并该页面并隐藏和显示游戏,根据时间消耗,它会有点复杂和昂贵。

我会建议第一个。 如果您在编码方面也需要帮助,请告诉我。 古德勒克