我在解决我的回复时遇到问题,但我的回复总是正确的。我正在提交一份忘记密码的表格,我只有一个字段,那就是电子邮件。我根据电子邮件在数据库中检查记录,如果返回记录,我将 json 设置为 true,否则设置为 false。这是我的 Codeigniter 控制器的代码:
public function checkEmail()
{
// set the validation rules
$this->form_validation->set_rules('checkemail', 'E-Mail', 'valid_email');
$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']
);
$currentUser = array();
$currentUser = $this->session->set_userdata($data);
echo json_encode(array("success" => "true"));
} else {
echo json_encode(array("success" => "false"));
}
// form validation has failed
} else {
$errorMessage = "Wrong email!";
}
} // end of function checkEmail
现在,当我检查我的 javascript 文件中的结果时,我总是正确的。这是代码:
$("#formSendPassword").submit(function(e){
e.preventDefault();
var email = $(this).find("#checkemail").val();
var obj = {email: email};
var url = $(this).attr("action");
$.post(url, obj, function(r){
if(r.success == "true") {
console.log(r.success);
$('#forgotPasswordForm').hide();
$('#successMailMessage').fadeIn()
} else {
$('#forgotPasswordForm').hide();
$('#errorMailMessage').fadeIn()
}
}, 'json')
})
任何人都可以帮我解决这个问题吗?
问候,佐兰