Answer the question
In order to leave comments, you need to log in
Why does Ajax return question marks (encoding issue)?
I'm not strong in javascript and all sorts of ajax, so I'll explain as best I can:
There is a form, the data from which is processed on a separate page and sent to e-mail, in case of successful sending, ajax should return something like "sent" to the page, but instead crocodile comes.
Script on the page
function SendForm(result_id,form_id,url) {
jQuery.ajax({
url: url, //Адрес подгружаемой страницы
type: "POST", //Тип запроса
dataType: "html", //Тип данных
data: jQuery("#"+form_id).serialize(),
success: function(response) { //Если все нормально
alert(response);
},
error: function(response) { //Если ошибка
alert('Ошибка!');
}
});
}
<?php $param1 = $_POST['name']; $param2 = $_POST['phone']; $param3 = $_POST['comm'];
header('Content-Type: text/html; charset=utf-8');
if (empty($param2)){ die('Введите телефон!'); };
$to = "Admin <****@yandex.ru>"; /* ТУТ ЕМЕИЛ */
$subject = "С лендинга";
$message = 'Имя: '.$param1.', Телефон: '.$param2.', E-Mail: '.$param3;
$mailheaders .= 'From: Landing <***@mail.ru>';
mail($to, $subject, $message, $mailheaders);
echo 'Спасибо, наш менеджер свяжется с вами.';
?>
Answer the question
In order to leave comments, you need to log in
What is the encoding of the php file with the script? Make sure it's exactly the same as the page. Ideally utf-8.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question