简体   繁体   中英

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. 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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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