Answer the question
In order to leave comments, you need to log in
How to get the value of the post parameter when sending mail via ajax request?
I send mail from the landing form.
On submit, it executes an ajax request with sending data to the php mail send file.
Everything works fine. Now I want to add identification by the POST request parameter, for example, by name.
I found a recommendation on how to do this.
<script type="text/javascript">
var $_POST = <?php echo json_encode($_POST); ?>;
document.write($_POST["name"]);
</script>
Answer the question
In order to leave comments, you need to log in
Apparently, you have to return json from the script to browsers.
Write before ?>
echo json_encode(['name' => $_POST['name']]);
And after ?> delete everything
As soon as it appears either before <?php or after ?> code of even empty opening and closing tags
?>
<script type="text/javascript">
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question