为什么每次页面加载都要执行google signin JavaScript函数

为什么每次页面加载都要执行google signin JavaScript函数,javascript,ajax,Javascript,Ajax,我在我的网站上使用谷歌API登录gmail,登录后,我使用Ajax调用将Id、用户名、电子邮件和图像url存储在数据库中,作为响应,显示模式。一切进展顺利,但如果用户在未注销的情况下关闭模式并重新加载页面,则每次刷新/重新加载页面时,我的onSignin函数都会执行 <div class="form-group"> <div class="g-signin2" data-onsuccess="onSignIn"></div> &

我在我的网站上使用谷歌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');
    }

函数onSignIn(谷歌用户){
var profile=googleUser.getBasicProfile();
var profile_Id=profile.getId();
var profile_Name=profile.getName();
var profile_Email=profile.getEmail();
var profile_Image=profile.getImageUrl();
//用于将配置文件信息保存到satrt的ajax调用
$.ajax({
键入:“POST”,
url:“../action.php”,
数据:{Id:profile\u Id,Name:profile\u Name,Email:profile\u Email,Image:profile\u Image},
成功:功能(响应){
console.log(“响应:+响应”);
$('#username').html(“Hi”+profile_Name+“!”);
document.getElementById(“登录”).style.visibility=“可见”;
$(“#ratingmodel”).model('show');
}
});
sessionStorage.setItem(“Id”,profile_Id);
$(“#LoginModal”).modal('hide');
}

您需要找到首先调用函数的位置。这只是函数定义。这是调用函数的地方,这是函数的唯一定义这是HTML,不是JS。试着在你的项目中找到“g-signin2”和“onsuccess”,我没有任何带有“g-signin2”或“onsuccess”的功能。但就我对用户成功登录的理解而言,上面的onSignIn函数执行。在onSignIn函数中,do console.trace()它将告诉您调用它的函数。总有一个开始