I have a button set up to refresh a certain div when it’s clicked. Problem is that it only works once.
The div that I need refreshing when the button is clicked:
<div id="refresh">
<?php include('space.php'); ?>
</div>
The script to refresh the div:
jQuery(function() {
jQuery("#go").click(function() {
jQuery("#refresh").load("space.php");
});
});
and the contents of space.php:
<?php
/* get disk space free (in bytes) */
$df = disk_free_space("/home");
/* and get disk space total (in bytes) */
$dt = disk_total_space("/home");
/* now we calculate the disk space used (in bytes) */
$du = $dt - $df;
/* percentage of disk used - this will be used to also set the width % of the progress bar */
$dp = sprintf('%.2f',($du / $dt) * 100);
/* and we formate the size from bytes to MB, GB, etc. */
$df = formatSize($df);
$du = formatSize($du);
$dt = formatSize($dt);
function formatSize( $bytes )
{
$types = array( 'B', 'KB', 'MB', 'GB', 'TB' );
for( $i = 0; $bytes >= 1024 && $i < ( count( $types ) -1 ); $bytes /= 1024, $i++ );
return( round( $bytes, 2 ) . " " . $types[$i] );
}
?>
<table class='ipb_table' cellspacing='1'>
<tr>
<td class='row2' colspan='2'>
<div class='progress'>
<div class='prgbar'></div>
</div>
</td>
<tr>
<td class='row2'>
Disk Space:
</td>
<td class='row2'>
<?php echo "$dt"; ?>
</td>
</tr>
<tr>
<td class='row2'>
Free:
</td>
<td class='row2'>
<?php echo "$df"; ?>
</td>
</tr>
<tr>
<td class='row2'>
Used:
</td>
<td class='row2'>
<?php echo "$du"; ?>
</td>
</tr>
<tr>
<td class='row2' colspan='2' align='center'>
<a class='ipsButton' id='go'>Refresh<a>
</td>
</tr>
</table>
Remove
<?php include('space.php'); ?>Jquery is fine.Test this out
jSfiddle
Make sure
space.phpis on the same server. And second thing is that.loadis not the replace ofphp include. Do this withjQuery Ajax