我已经创建了一个简单的代码ajax请求,用于检查codeigniter框架中的电子邮件可用性.但是,我每次都会得到错误.并且不知道如何解决它.下面是我的页脚js脚本(在jquery和其他外部脚本之后).
<script>
$(document).ready(function() {
$("#loading").hide();
$("#email").blur(function() {
var email_val = $("#email").val();
var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
if (filter.test(email_val)) {
// show loader
$('#loading').show();
jQuery.ajax({
type: "POST",
url: "<?php echo site_url()?>users/check_email_ajax",
dataType: 'json',
data: {
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>',
'email': 'email_val'
},
success: function (response) {
if(response){
$('#loading').hide();
console.log(response.message);
$('#msg').html(response.message)
$('#msg').show().delay(10000).fadeOut();
}
},
error: function(error){
$('#loading').hide();
console.log("There is some errors on server : " + error.error);
}
})
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的用户控制器功能,用于检查数据库中的电子邮件
public function check_email_ajax(){
// allow …Run Code Online (Sandbox Code Playgroud)