在我看来,我试图从 codeigniter 控制器获得响应,但没有成功。这是我的 javascript 文件中的代码:
// user enter his e-mail so check him against the database.
$("#formSendPassword").submit(function(e){
e.preventDefault();
var email = $(this).find("#checkemail").val();
var obj = {email: email};
var url = $(this).attr("action");
var data = {email: email};
$.post(url, obj,data, function(jsonResp){
console.log(success);
if(jsonResp.success) {
alert(jsonResp['success']);
$('#successMailMessage').fadeIn();
} else {
alert("Fail");
$('#errorMailMessage').fadeIn();
}
}, 'json');
})
我的控制器中的代码如下:
public function checkEmail()
{
// set the validation rules
$this->form_validation->set_rules('checkemail', 'E-Mail', 'valid_email|required|trim|encode_php_tags');
$this->form_validation->set_error_delimiters('<br /><p class=jsdiserr>', '</p><br />');
// if validation is passed
if ($this->form_validation->run() != FALSE)
{
$ids=array();
$ids[0]=$this->db->where('email', $this->input->post('checkemail'));
$query = $this->backOfficeUsersModel->get();
if($query)
{
$data = array(
'userid' => $query[0]['userid'],
'username' => $query[0]['username'],
'password' => $query[0]['password'],
'firstname' => $query[0]['firstname'],
'lastname' => $query[0]['lastname'],
'email' => $query[0]['email']
);
$jsonResp['success'] = "Ok";
$jsonResp = array();
} else {
// echo json_encode(array("success" => false, "error" => "Wrong email"));
$jsonResp['success'] = "Fail";
}
// form validation has failed
} else {
$errorMessage = "Please enter valid e-mail";
}
} // end of function checkEmail
如您所见,我试图在我的 js 文件中 console.log 成功,但没有成功。谁能告诉我我做错了什么?
问候,佐兰