0
config:$ config ['base_url'] = 'http://localhost/myApp/';POST http:// localhost/MyApp/MyCon/customerCheck 500(内部サーバーエラー)
電子メールがデータベースに既に存在するかどうかを確認します。私はコントローラのビューとして与えられた登録フォームの入力フィールドのonblur関数(emailCheck())を呼び出しました。
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();
}
}
?>
ログを確認してください。 –
@ Fred-ii-これらの2つのエラーがあります 未定義のプロパティ:MyApp :: $ customerModel C:\ wamp \ www \ myApp \ application \ controllers \ MyApp.php& nullのメンバー関数customerMailCheck()を呼び出す –
ウェルロードコールは明らかに失敗しました。 CIの命名規則... 'class Customer_model'と' - > model( 'customer_model') 'と思われるでしょうか?その後、 '$ this-> customer_model-> foo()'と一緒に使用してください。 – ficuscr