您好我通过ajax检查电子邮件问题,它总是让我得到内部错误500
edituser.php:
<form class="fcms" name="fcms" action="<?php echo base_url(); ?>cuser/newUser" method="POST" role="form">
<div class="row">
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-12">
<label><strong>Email: *</strong></label>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
<input type="email" name="email" id="email" value="" required />
<span id="email_result"></span>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<button type="submit" name="boton" onClick="javascript:Validar();">Registrer</button>
</div>
</div>
</form>
<script>
var baseurl = "<?php echo base_url(); ?>";
$(document).ready(function(){
$('#email').change(function(){
var email = $('#email').val();
if(email != '')
{
$.ajax({
url:baseurl+"cuser/email_check", // here goes to the controller
method:"POST",
data:{email:email},
success:function(data){
if(data.status=="success"){
$('#email_result').html(data);
}else{
console.log(data)
}
}
});
}
});
});
</script>
控制器:cuser
public function email_check(){
if(!filter_val($_POST["email"], FILTER_VALIDATE_EMAIL)){
echo 'Invalid Email';
}else{
$this->load->model('muser');
if($this->muser->is_email_available($_POST["email"])){
echo 'Email Already register';
}else{
echo 'Email Available';
}
}
}
型号:muser
public function is_email_available($email){
$this->db->where('email', $email);
$query = $this->db->get("admin"); // database
if($query->num_rows() > 0){
return true;
}else{
return false;
}
}
检查电子邮件时,控制台日志会返回错误: POST http://localhost/webs/admin/cuser/email_check 500(内部服务器错误)
感谢。