我正在使用ajax调用发送电子邮件,一切正常,电子邮件发送没有任何问题。但是ajax调用完成后没有执行.done函数......它正在执行.fail函数但我无法理解为什么!!如果它的工作绝对正常,为什么执行.fail函数?请帮助我,这是我的代码:
AJAX
$('#send_mail').submit(function(e) {
e.preventDefault();
$.ajax({
url: baseurl+'email/send',
type: 'POST',
dataType: 'json',
data: $(this).serialize()
})
.done(function(data){
alert("que wea");
})
.fail(function(data){
alert("chango");
});
});
});
CONTROLLER
if( $this->input->is_ajax_request()){
$captcha_answer = $this->input->post('g-recaptcha-response');
$result = $this->validar($captcha_answer);
if ($result == 1) {
$mail = $this->input->post('contact_mail');
$name = $this->input->post('contact_name');
$msg = $this->input->post('contact_message');
$config = array(
'protocol' => 'esmtp',
'smtp_host'=> 'mail.novaderma.cl',
'smtp_port'=> 26,
'smtp_user'=> 'contacto@novaderma.cl',
'smtp_pass'=> '******',
'mailtype'=> 'html',
'charset'=> 'utf-8',
'newline' => '\r\n',
'crlf' => '\n'
);
$this->email->initialize($config);
$this->email->from($mail);
$this->email->to('contacto@novaderma.cl');
$this->email->subject('IMPORTANTE CORREO CONTACTO');
$this->email->message('<h2>PÁGINA NOVADERMA</h2>
<hr><br>
<br>
<p>'.$msg.'</p>
');
if ($this->email->send()) {
echo json_encode( array('success' => 1));
}
else {
echo json_encode( array('success' => 0));
}
/*echo $this->email->print_debugger();*/
}
else {
}
}