我试图找到在网页上刷新PHP变量的方法,而无需再次重新加载整个页面,我只是想以设定的速率更新响应变量。如有任何帮助,不胜感激。
echo "Speed: " . ($APIkbpersec) . " KB/s";
您需要将该函数放在单独的文件中,并使用AJAX请求来更新它。标准是jQuery,所以我将展示一个非常基本的使用示例。
http://jquery.com/<div id="Update">This will be updated</div>
$("#Update").load('YourUpdateScript.php');
这将请求php脚本并将内容放入名为"Update"的div中。
要让它定期更新,你需要设置一个计时器:
// This is run when the document is ready, you could also run setInterval elsewhere if needed
$(document).ready(function (e) {
setInterval ( RunUpdate, 3000 ); // Run once every 3 seconds
});
function RunUpdate() {
$("#Update").load('YourUpdateScript.php');
}
页面刷新或调用clearInterval()将停止它的运行