0

我有一个按钮设置为在单击某个 div 时刷新它。问题是它只能工作一次。

单击按钮时我需要刷新的 div:

<div id="refresh">

    <?php include('space.php'); ?>

</div>

刷新 div 的脚本:

jQuery(function() {
    jQuery("#go").click(function() {
        jQuery("#refresh").load("space.php");
    });
});

和 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>   
4

2 回答 2

0

试试这个,它可能会起作用。

jQuery(function() {
    jQuery("#go").on('click', function() {
        jQuery("#refresh").load("space.php");
    });
});​
于 2012-05-13T16:56:57.573 回答
0

删除<?php include('space.php'); ?>
Jquery 很好。测试一下

    jQuery(function() {
    var i=1;
    jQuery("#go").click(function() {
        jQuery("#refresh").html(i);
        i++;
    });
});​

jSfiddle

确保space.php在同一台服务器上。第二件事是那.load不是替换php include. 这样做jQuery Ajax

于 2012-05-13T16:57:56.653 回答