如何将变量从JavaScript发送到php文件?

时间:2018-06-21 14:55:45

标签: javascript php

例如我有一个变量

var test = "done";

如何将其发送到php?然后发布

1 个答案:

答案 0 :(得分:0)

尝试使用此代码

<script>
 var test = "done";
 document.getElementById('sample').value = test;
</script>

<form method = "post">
   <input type="hidden" id="sample" name="stext">
   <input type="submit" name="submit" value="submit">
</form>

<?php
 echo $_POST['stext'];
?>