How to get response after ajax request?

there is a feedback form. Processing via ajax. Letters in the mail. But I can not understand how a successful send to get the message that everything is OK Tell me, what's wrong?
Here is the code:
$('form.mod_f').submit(function(event){
event.preventDefault();
 var formID = $(this).attr('id');
 var formNm = $('#' + formID);
 // send the data
$.ajax({
 url: "/mail.php",
 type: "post",
 dataType: "json",
 data: formNm.serialize(),
 success: function(data){
$('.answer').html(data);
},
});
 });


the php file:
<?php
$method = $_SERVER['REQUEST_METHOD'];

$c = true;
if ( $method === 'POST' ) {

 $project_name = "#######";
 $admin_email = "######";
 $form_subject = "########";

 foreach ($_POST as $key =--> $value) {
 if ($value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject") {
 $message .= "
 ". (($c = !$c) ? ": ") . "
<b>$key</b>
$value

";
}
}
}
$message = "$message<table style="width: 100%;"></table>";

function adopt($text) {
 return '=?UTF-8?B?'.base64_encode($text).'?=';
}
$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
'Reply-To: '.$admin_email." . PHP_EOL;

mail($admin_email, adopt($form_subject), $message, $headers );

echo "good";
July 2nd 19 at 13:19
1 answer
July 2nd 19 at 13:21
Solution
success: function(data){
$('.answer').html(data);
},


Here you have the conclusion, there is a class on the page?
yeah, so I do not understand what the problem is. - Will_Mertz commented on July 2nd 19 at 13:24
: check in the console the data.
success: function(data){
console.log(data)
$('.answer').html(data);
},

Displays "good"?
If Yes, check the presence of the class .answer, but rather properly:. MB Russian symbol is jammed or something. - Armando91 commented on July 2nd 19 at 13:27
: so $('.answer').length > 0 ? - gustave_Kertzmann52 commented on July 2nd 19 at 13:30
: change dataType: "html" - terrell_Prohaska68 commented on July 2nd 19 at 13:33
: Yes, returns true - Will_Mertz commented on July 2nd 19 at 13:36
: well, if you have performed success, then what is the problem. - gustave_Kertzmann52 commented on July 2nd 19 at 13:39
in the console nothing appears. - Will_Mertz commented on July 2nd 19 at 13:42
: changed type, has helped, thank you. - Will_Mertz commented on July 2nd 19 at 13:45

Find more questions by tags HTMLjQueryAJAX