Answer the question
In order to leave comments, you need to log in
How to pass js variable value to php variable?
Hello! Tell me how to pass the value of a variable from a js script to a php variable
Tried to do this
$(document).ready(function () {
ymaps.ready(function () {
var geolocation = ymaps.geolocation;
var region = geolocation.region;
$.ajax({
url: "1.php",
type: "POST",
data: {region:region}
});
});
});
$regionprimer = $_POST['region'];
echo $regionprimer;
Answer the question
In order to leave comments, you need to log in
Is the letter sent by filling out some form? You can insert the region value into input[type=hidden] on the form, and send data from it to the script that sends the email. And in the script, the variable will already be available in $_POST
You sent an Ajax request to a file and that's the end of the story.
Then no matter how much you open the file, it will be so with an empty variable.
You need to send a request to a file in which the variable will be saved, and in another file the SAVED variable will be displayed. How to save? Lots of options: $_SESSION, setcookie(), write to a file or database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question