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);
}
});
});
答案 0 :(得分:0)
如果您不需要刷新,则只需添加代码即可实现此目的。
我会建议第一个。 如果您在编码方面也需要帮助,请告诉我。 古德勒克