[英]Updating (refreshing) PHP variable without refreshing website
I am trying to make updating variable called $online without refreshing site.我正在尝试在不刷新站点的情况下更新名为 $online 的变量。
Theres is my try:这是我的尝试:
data.php数据.php
<?php
include("steam.php");
$data = $online;// obtain current value of data from somewhere
echo $data; // should be an integer
?>
refresh.js刷新.js
$(document).ready( function () {
var data = []; // data is empty
var graph = Morris.Bar({
element: 'graph',
data: data
labels: ['random label']
});
function update () {
$.getJSON( "data.php", function (newv) {
data.push( { x: newv, y: "Today" } ); // store new value
graph.setData( data ); // update the graph
});
}
update();
setInterval( update, 1000 );
});
I just ran this through so I know it works.我刚刚完成了这个,所以我知道它有效。 My previous comment will do the job.我之前的评论将完成这项工作。 I know $.getJSON is similar so I don't know what conflicts you will have there, but the below will update your php variable.我知道 $.getJSON 是相似的,所以我不知道你会有什么冲突,但下面会更新你的 php 变量。
<script>
$.post( "data.php", { online: "UpdatedData" } );
</script>
data.php数据.php
$online = $_POST['online'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.