我有一个外壳脚本,这是在一个php文件中执行,以获得温度。
<?php
$output = shell_exec('sh temperature.sh');
echo "<pre>$output°C</pre>";
?>现在它只被执行一次。如何更改php文件以使其值始终是最新的?
谢谢
发布于 2014-10-11 01:02:11
PHP是一种服务器端语言。这意味着当它被加载时,它就完成了。如果你想总是更新它,你应该使用ajax调用。
var interval = 1000; // 1 second
function doAjax() {
$.ajax({
type: 'GET',
url: 'get_what_you_want.php',
data: {},
dataType: 'json',
success: function (data) {
$('body').text(data) // or put it on your page
},
complete: function (data) {
// Schedule the next
setTimeout(doAjax, interval);
}
});
}
setTimeout(doAjax, interval);https://stackoverflow.com/questions/26303730
复制相似问题