K
K
ksurill2014-01-17 19:59:15
JavaScript
ksurill, 2014-01-17 19:59:15

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

<?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 'Спасибо, наш менеджер свяжется с вами.';
?>


What can I do to make the script output the answer in normal encoding and not with questions?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
aen, 2014-01-17
@ksurill

What is the encoding of the php file with the script? Make sure it's exactly the same as the page. Ideally utf-8.

_
_ _, 2014-01-17
@AMar4enko

Try putting Content-Type text/plain in the header of the output

_
_ _, 2014-01-17
@AMar4enko

Ha, well, because you are not giving html. Try
or share json

dataType: 'json',
data: jQuery("#"+form_id).serialize(),
success: function(response) { //Если все нормально
            alert(response.message);
},

echo json_encode(array('message' => 'Спасибо и.т.д'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question