converting js variable to php [duplicate]
Possible Duplicate:
javascript variable into php
Okay lets imagine I've a javascript variable "x"
<script>
var x="jsvar";
</script>
Now I want its value in php variable $y
<?php $y; ?>
How to do it.
Okay few people ar开发者_开发技巧e confused i wanted to know is it possible if yes then how ?? if this isn't possible then comment here i'll remove it.
You have to pass it to your PHP script, either via AJAX or via a formular with a submit button.
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){}; // change
xhr.open("POST", "your-script.php");
xhr.send("x="+x);
And the PHP script can look like this:
<?php
$y = isset($_POST['x']) ? $_POST['x'] : '';
echo $y;
?>
精彩评论