控制器显示输出错误1它甚至不会拖拽行(),并且在开发人员工具中不会出现任何错误。它从ajax users_controller获取文件,但不起作用&问题很严重。
这是表格:
<form class="form-signin" >
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="name" class="sr-only">Username</label>
<input type="text" id="name" class="form-control" placeholder="Username" autofocus><br/>
<label for="Password" class="sr-only">Password</label>
<input type="text" id="password" class="form-control" placeholder="Password">
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
<span class="error"></span>
</form>
这些是脚本:
<script>
$(document).ready(function(){
$('form').on('submit',function(){
var username = $('#name').val();
var password = $('#password').val();
$.ajax({
type:'post',
url:'users_controller/login_check',
data: {
username:'username',
password:'password'
},
success:function(result)
{
if(result !== 'error')
{
window.location.href=result;
}
else
{
$('.error').html('');
$('.error').html('<p class="alert alert-danger">Invalid username or password</p>');
$('.error').show();
}
}
});
return false;
});
});
这是控制器文件:
public function login_check()
{
$username = $this->input->post('username',TRUE);
$password = $this->input->post('password',TRUE);
$this->load->model('users_model');
//$row = $this->load->users_model('getUsers');
$row = $this->users_model->getUsers($username,$password);
if($row)
{
if($this->username === $username && $this->password === $password)
{
$this->session->set_userdata('user_id',$row->user_id);
$this->session->set_userdata('user_name',$row->username);
echo base_url('users_controller');
}
else
{
echo "error";
}
}
else{
echo "error1";
print_r($row);
}
}
控制器显示输出错误1它甚至不会拖拽行(),并且不会在开发人员工具中出现任何错误。