如何使用PHP在页面中动态定义Javascript传递的变量


How to define the variables passed by Javascript in the page dynamically using PHP?

这是我的代码,我在其中使用了自动刷新timing.php的加载函数。

<script>
var auto_refresh = setInterval(function()
{ $('#myDiv').load('timing.php?test=<?php echo $test?>');
}, 1000);
</script>

我的表格是,

<form id="formElem" name="formElem" action="<?php $_SERVER['PHP_SELF'];?> " method="get">

我想把动态变量作为发送

<?php 
if(isset($_GET['view_det'])) 
{ 
$test=$row2['test_name'];
?>
<p id="myDiv"> </p>

请帮帮我。

timing.php?test=<?php echo $test?>

这意味着timing.php将期望一个名为test的GET参数。在timing.php上,可以这样访问参数:

<?php
$test = $_GET['test'];