我在我的网站上使用Google API使用gmail登录,登录后使用Ajax调用在数据库中存储ID,用户名,电子邮件和图片url,并显示模式信息。一切正常,但是如果用户关闭模式但不注销并重新加载页面,则每次刷新/重新加载页面时,我的onSignin函数都会执行。
<div class="form-group">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</div>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var profile_Id = profile.getId();
var profile_Name = profile.getName();
var profile_Email = profile.getEmail();
var profile_Image = profile.getImageUrl();
//ajax call for saving profile information satrt
$.ajax({
type: 'POST',
url: '../action.php',
data: {Id:profile_Id, Name:profile_Name, Email:profile_Email, Image:profile_Image},
success: function(response) {
console.log("Response: " + response);
$('#username').html("Hi "+profile_Name+"!");
document.getElementById("sign-in").style.visibility = "visible";
$('#RatingModal').modal('show');
}
});
sessionStorage.setItem("Id", profile_Id);
$("#LoginModal").modal('hide');
}