jQuery验证成功后,页面不会在特定位置重定向

在我的代码中,我正在做jQuery验证,它将会成功,但是当它重定向页面时,它不会重定向到给定的url。 当我检查这使用萤火虫它显示每个正确的领域,也是HTML(给定的网址)。 我不知道如何重定向页面。

在成功我只想打开我的admin_login /登录页面,如果验证失败,它会在admin_login / index页面上。

 <?php include('assets/header.php'); ?> 

<div class="container">
    <h1>Welcome to Admin Login</h1>
    <?if($this->session->flashdata('flashError')):?>
    <p class='flashMsg flashError'> 
        <?= $this->session->flashdata('flashError') ?> </p>
    <?endif?>
    <!-- new line inserted -->
    <form method="post" name="myForm" accept-charset="utf-8"   class="login" id="form" >
        <div class="form-group">
            <div class="col-xs-4">
                <!--<label for="admin">Admin</label>
                <input type="text" name="admin" class="form-control" id="admin" value=""  placeholder="admin name" />-->
                Admin Name: <input type="text" name="admin" id="admin" class="form-control"  value="<?php echo set_value('admin'); ?>"  placeholder="admin name" >
                <?php echo form_error("admin"); ?>
                <p id='p1'></p>
                <br>
                <!--  <label for="password">password</label>
                 <input type="text" name="password" class="form-control" id="password" value=""  placeholder="password" required/>
                -->
                Admin Password: <input type="password" name="password" id="password" class="form-control" value=""  placeholder="password" >
                <?php echo form_error("password"); ?>
                <p id='p2'></p>
                <br>
                <br>
                <input type="button" name="submit" value="submit" id="submit" class="btn btn-primary"  >
            </div>
        </div>
        <div class="error"></div>
    </form> 
</div>

<script>
    $(document).ready(function () {
        $("#submit").click(function () {
            var admin = $("#admin").val();
            var password = $("#password").val();

            $("#returnmessage").empty(); // To empty previous error/success message.
            // Checking for blank fields.
            if (admin == '')
            {
                $('div.error').html("Please Fill Admin Required Fields");
            } else if (password == '')
            {
                $('div.error').html("Please Fill Password Required Fields");
            } else
            {//alert('hello world');
                // Returns successful data submission message when the entered information is stored in database.
                $.ajax({
                    type: "POST",
                    url: "<?php base_url() ?>index.php/admin_login/login",
                    data: {"admin": admin, "password": password},
                    dataType: "json"

                }).done(function (data) {
                    if (data.error != "")
                    {
                        //alert('hello if');
                        $('div.error').html(data.error);
                    } else
                    {

                       // alert('hello else');
                        window.location.href="admin_view";
                    }

                });
            }
        });
    });
</script>


<?php include('assets/footer.php'); ?>

尝试这个

 here full path like this 

window.location.assign("http://localhost/ss.php");

要么

window.location.assign("<?php base_url() ?>index.php/admin_login/login");

您将获得成功功能的响应。

             $.ajax({
                type: "POST",
                url: "<?php base_url() ?>index.php/admin_login/login",
                data: {"admin": admin, "password": password},
                dataType: "json"
                success : function (data) {
                // alert('hello else');
                    window.location.href="<?php base_url() ?>index.php/admin_login/login";
                },
                error: function() {
                     $('div.error').html("An error occurred");
                }

            });

尝试使用完整的网址

window.location.href="<?php base_url() ?>index.php/admin_login/login";
链接地址: http://www.djcxy.com/p/34745.html

上一篇: on success of jquery validation the page not redirect on specific location

下一篇: How to use link instead of alert?