config:$ config ['base_url'] ='http://localhost/myApp/';

我想检查电子邮件是否已经存在于数据库中。我已经以注册表格的形式调用了输入字段的function(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();
        }
    }
?>

最佳答案

$res = $this->customerModel->customerMailCheck($mail);


如果型号名称区分大小写,则应为

$res = $this->CustomerModel->customerMailCheck($mail);

10-08 08:59
查看更多