我有一个表格,可以在我的流程页面上评估数据库中的信息,并在必要时返回错误。我正在使用 Ajax,所以它实际上不应该进入流程页面并加载我在 Json 中编码的内容以返回。这是我的表格加上Javascript:
<form method="post" action="../user/process_login" id="login_form">
<input type="hidden" name="action" value="login">
<label>Email Address:</label>
<input type="text" id="email" name="email" placeholder="Email" />
<label>Password:</label>
<input type="password" id="password1" name="password0" placeholder="Password" />
<input type="submit" id="submitbtn" placeholder="Submit" class="button"/>
</form>
Javascript:
<script type="text/javascript">
$(document).ready(function(){
$('#login_form').submit(function(){
$.post
(
$(this).attr('action'),
$(this).serialize(),
function(data){
if (data['errors'] == '') {
consle.log(data);
};
else{
console.log(data);
$('#alert_box').html(data);
};
},
"json"
);
return false;
});
});
</script>
这是我的验证代码的相关部分:
if (count($user) > 0 AND $decrypted_password == $this->input->post('password0'))
{
$this->session->set_userdata('user_session', $user);
$this->load->view('main.php');
}
else
{
$errors = "<div class='alert-box alert' id='error-box'><p>Your login information did not match our reccords. Try again</p></div>";
echo json_encode($errors);
}