简体   繁体   中英

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. 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. 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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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