Witam mam problem z odpowiedzią z php mailer do ajax a mianowicie przesyła się z ajax wszystko super zapisuje do bazy bez problemu i email się też wysyła normalnie.
ale w konsoli dostaje XHR failed loading: POST.
i po success: to co jest się nie wykonuje
chodź reszta czyli zapis do bazy i wysłanie e-maila się bez problemu dokonują
console.log(data.response); zwraca undefined
plik.php
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 0;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "[email protected]";
$mail->Password = "xxxxxxxxx";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "[email protected]";
$mail->FromName = "Full Name";
$mail->addAddress("[email protected]", "tester");
$mail->isHTML(true);
$mail->Subject = "test";
$mail->Body = "<i>test</i>";
$mail->AltBody = "This is the plain text version of the email content";
if($mail->send()){
header('Content-type: application/json');
echo json_encode(array('response' => 'success'));
}
plik.js
$.ajax({
type: "POST",
url: "include/plik.php",
dataType: "json",
data: {imie:imie, nazwisko:nazwisko}, //zmieniłem to nadal to samo
success: function(data){
if(data.response == "success"){
alert("nie ma problemu!");
}
}
});