config:$ config ['base_url'] ='http://localhost/myApp/';
我想检查电子邮件是否已存在于数据库中。我在注册表单中调用了一个输入字段的函数(emailCheck())onblur,它在控制器中作为视图给出。
AJAX代码:
function emailCheck(){
var email = jQuery("#email").val();;
jQuery.ajax({
type: 'POST',
url: "<?php echo site_url(); ?>myCon/customerCheck",
data: {"email":email},
success:function(response){
if(response.status=="success"){
$('#test').html(response.message);
} else {
console.log(response.message)
}
}
});
}
控制器代码:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
*
*/
class MyCon extends CI_Controller
{
public function customerCheck(){
if ($this->input->is_ajax_request()) {
$this->load->model('CustomerModel');
$mail = $this->input->post('email');
$res = $this->customerModel->customerMailCheck($mail);
if(!empty($res)) {
$data['status'] = 'success';
$data['message'] = 'Email Adress is found';
} else {
$data['status'] = 'error';
$data['message'] = 'Data not found';
}
echo json_encode($data);
exit;
} else{
redirect('somelink');
}
}
}
?>
型号代码:
<?php
class CustomerModel extends CI_Model{
function __construct()
{
parent:: __construct();
}
function customerMailCheck($mail){
$result = $this->db->get_where('privilege_customer', array('email' => $mail));
return $result->result();
}
}
?>
答案 0 :(得分:0)
$res = $this->customerModel->customerMailCheck($mail);
如果型号名称是敏感的,那么它应该是
$res = $this->CustomerModel->customerMailCheck($mail);