简体   繁体   English

在 ajax 中成功登录后未重定向登录弹出窗口

[英]Login popup not redirected after successful login in ajax

I trying a popup on clicking login window a pop up open with URL it asking for username and password as well as google signin When the user tries to login using google sign in using pop up.我尝试在单击登录 window 时弹出一个弹出窗口,该弹出窗口打开 URL 它询问用户名和密码以及谷歌登录当用户尝试使用谷歌登录时使用弹出窗口登录。 After login the popup never redirects to the main page.登录后,弹出窗口永远不会重定向到主页。 But alert box with posting failed keeps on appearing但是发布失败的警告框不断出现

 <button class="btn btn-primary btn-lg" href="#signup" data-toggle="modal" data-target=".log-sign">Sign In/Register</button>

 <div class="modal-body">
        <div id="myTabContent" class="tab-content">
       
        <div class="tab-pane fade active in" id="signin">
            <form class="form-horizontal" action="" method="post">
            <fieldset>
            <!-- Sign In Form -->
            <!-- Text input-->
              
               <div class="group">
<input required="" class="input" type="text"><span class="highlight"></span><span class="bar"></span>
    <label class="label" for="date">Email address</label></div>
              
              
          
            <div class="group">
<input required="" class="input" type="password"><span class="highlight"></span><span class="bar"></span>
    <label class="label" for="date">Password</label>
    </div>


   
               <div class="or-box">
                    <span class="or">OR</span>
                    <div class="row">
                        <div class="col-md-12">
                            <center><div class="g-signin2" data-onsuccess="onSignIn"></div></center>
                        </div>
                    </div>
                </div>

            <!-- Button -->
            <div class="control-group">
              <label class="control-label" for="signin"></label>
              <div class="controls">
                <button id="signin" name="signin" class="btn btn-primary btn-block">Log In</button>
              </div>
            </div>
            </fieldset>
            </form>
        </div>

<script type="text/javascript">
    function onSignIn(googleUser) {
      var profile = googleUser.getBasicProfile();


      if(profile){
          $.ajax({
                type: 'POST',
                url: 'login_pro.php',
                data: {id:profile.getId(), name:profile.getName(), email:profile.getEmail()}
            }).done(function(data){
                console.log(data);
                window.location.href = 'index.php';
            }).fail(function() { 
                alert( "Posting failed." );
            });
      }


    }
</script>

You can try some of these:您可以尝试其中一些:

  1. check whether it reaches the success block or not检查它是否到达成功块

  2. if it does try replacing如果它确实尝试更换

    window.location.href = 'comments.php';

    with window.location.href = '/comments.php';

  3. Or just simulate an Http redirect using: window.location.replace("www.abc.com/comments.php");或者只是使用以下命令模拟 Http 重定向: window.location.replace("www.abc.com/comments.php");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM