简体   繁体   English

我如何刷新以下php文件? (不重新加载页面)

[英]How could I refresh the following the php file? (Without the page reloading)

I've been playing around creating a control panel for gameservers, however I would love to show the user some CPU percentages. 我一直在为游戏服务器创建控制面板,但是我希望向用户展示一些CPU百分比。 I totally can, but it doesn't update itself automatically. 我完全可以,但是它不会自动更新。 Here are my Codes Note: This is not a working code, I mean it works, but only if you have load.php, which totally works, so I'm not going to bother showing it, it basically returns a number + %, to be able to modify the width of the progress bar. 这是我的代码注意:这不是一个有效的代码,我的意思是它可以工作,但是只有当您具有完全可以工作的load.php时,因此我不花心去显示它,它基本上返回一个数字+%,才能修改进度条的宽度。 What I want is pretty simple, I want the bar to update itself automatically. 我想要的很简单, 我希望栏会自动更新。 I just don't know why my code doesn't work. 我只是不知道为什么我的代码不起作用。

<?php include '../includes/kezelohead.php'; ?>
<?php 
include 'load.php';
//echo $cpu;
?>
<h5>Processzor Hasznalat</h5>

<div class="progress progress-striped" id="prog">
  <div id='bar' class='progress-bar progress-bar-custom active' role='progressbar' aria-valuemin='0' aria-valuemax='100' style="width:100%;">
  </div>
<script type="text/javascript">
var interval = setInterval(cpu, 2000);
function cpu() {
  $("#scores").load("load.php #scores");
  var data = <?php echo(json_encode($cpu)); ?>;
  document.getElementById('bar').style.width = data;
  //setTimeout(yourFunction, 5000);
}
</script>
<div id='scores'>
<?php 
include 'load.php';
//echo $cpu;
?>
</div>

我已经设法用AJAX解决了这个问题,所以谢谢大家:)我使用了Ajax的load函数,例如: $('#scores').load('load.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM