Answer the question
In order to leave comments, you need to log in
I don’t understand where I’m losing JSON when transferring to the server, let’s look together?
I send the string to the server:
var msg = {},
str;
msg.name = name.value;
msg.mail = mail.value;
msg.phone = phone.value;
msg.select = select;
msg.comment = comment;
str = JSON.stringify(msg);
//msg = serialize(document.querySelector('form'));
var xhr = new XMLHttpRequest();
// 2. Конфигурируем его: POST-запрос на URL 'mail.php'
xhr.open('POST', 'mail.php', true);
xhr.addEventListener('load', function() {
if (xhr.status != 200) {
// обработать ошибку
alert( xhr.status + ': ' + xhr.statusText ); // пример вывода: 404: Not Found
} else {
document.querySelector('.form__content').style.display = 'none';
document.querySelector('.form-successful').style.display = 'block';
}
});
xhr.send(str);
console.log(str);
$obj = json_decode($_POST, true);
$to = "[email protected]";
$subject = "Заявка";
$from = "[email protected]";
$headers = "From: $from";
mail($to,$subject,$obj[name],$headers);
echo "Mail Sent.";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question