开发者

converting js variable to php [duplicate]

This question already has answers here: Closed 11 years ago.

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;

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜