javascript - 新手需要强制php页面重新加载一次
问题描述
我有这个 php 文件,我用它来控制连接到 Raspberry pi 的 gpio 引脚的继电器。我工作得很好,只是当 gpio 引脚更改状态时图标不会按需要更新。如果我单击浏览器上的 RELOAD 按钮,它们会根据需要进行更新。我尝试过使用:location.reload(true),但只有当我将它作为自己的按钮放在页面代码的 html 部分中时它才有效。每当我单击其中一个 gpio 图标时,我希望 location.reload(true) 执行。有人可以帮我弄这个吗?提前感谢新手。
这是我正在使用的 php 代码:
<!DOCTYPE html>
<!--TheFreeElectron 2015, http://www.instructables.com/member/TheFreeElectron/ -->
<html>
<head>
<meta charset="utf-8" />
<title>Antenna Relays</title>
</head>
<body style="background-color: black;">
<h1><p style="color:white"><font size="7">
    ANTENNA SELECTOR
</p>
</font></h1>
<!-- On/Off button's picture -->
<?php
$val_array = array(0,0,0,0);
//this php script generate the first page in function of the file
for ( $i= 0; $i<4; $i++) {
//set the pin's mode to output and read them
system("gpio mode ".$i." out");
exec ("gpio read ".$i, $val_array[$i], $return );
}
//for loop to read the value
$i =0;
for ($i = 0; $i < 4; $i++) {
//if off
if ($val_array[$i][0] == 0 ) {
echo ("<img id='button_".$i."' src='data/img/red/red_".$i.".jpg' onclick='change_pin (".$i.");'/>");
}
//if on
if ($val_array[$i][0] == 1 ) {
echo ("<img id='button_".$i."' src='data/img/green/green_".$i.".jpg' onclick='change_pin (".$i.");'/>");
}
}
?>
<!-- javascript -->
<script src="script.js"></script>
</body>
</html>