在我的编码中,我正在进行jQuery验证,这是成功的但是当它重定向页面时它不会重定向给定的URL。当我使用firebug检查它时,它显示每个正确的字段和html(给定的URL)。我不知道如何重定向页面。
成功之后我只想打开我的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'); ?>
答案 0 :(得分:1)
试试这个
here full path like this
window.location.assign("http://localhost/ss.php");
或
window.location.assign("<?php base_url() ?>index.php/admin_login/login");
答案 1 :(得分:0)
您将获得成功功能的响应。
$.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");
}
});
答案 2 :(得分:0)
尝试使用完整网址
window.location.href="<?php base_url() ?>index.php/admin_login/login";