Tôi đã tạo một yêu cầu ajax mã đơn giản để kiểm tra tính khả dụng của email trong khung công tác viết mã. nhưng, tôi nhận được mọi lỗi. và không biết cách giải quyết nó. bên dưới là tập lệnh js chân trang của tôi (sau jquery và các tập lệnh ngoài khác).kiểm tra email người dùng mã lỗi ajax
<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_-][email protected][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);
}
})
}
});
});
và đây là chức năng điều khiển tài khoản của tôi để kiểm tra email trong db
public function check_email_ajax(){
// allow only Ajax request
if($this->input->is_ajax_request()) {
// grab the email value from the post variable.
$email = $this->input->post('email');
// check in database - table name : users , Field name in the table : email
if(!$this->form_validation->is_unique($email, 'users.email')) {
// set the json object as output
$this->output->set_content_type('application/json')->set_output(json_encode(array('message' => 'The email is already taken, choose another one')));
}else{
$this->output->set_content_type('application/json')->set_output(json_encode(array('message' => 'you can use this email')));
}
}
}
và theo hình thức đăng ký tôi có lĩnh vực này cho đầu vào email:
<div class="col-sm-5">
<input type="email" id="email" name="email" class="form-control">
<span id="loading"><img src="<?php echo base_url(); ?>ajax-loader.gif" alt="Ajax Indicator" /></span>
<div id="msg"></div>
</div>
nhưng bây giờ mỗi lần tôi thay đổi giá trị của đầu vào. Tôi gặp lỗi trên console.log
There is some errors on server : function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
có ai biết cách khắc phục không?
Vui lòng mở bảng điều khiển web của bạn và thêm ảnh chụp màn hình tiêu đề/phản hồi yêu cầu của bạn và JSON nhận được chức năng ajax của bạn được đăng –
Ngoài ra, bạn có thể thêm đầu ra của console.log (lỗi); –