开发者

How to update jQuery Progress bar according to a value at the session variable in PHP

I need to fill the progress bar according to the current value of a session variable. The value will be not be constant and is increasing. How to make it load by itself?

<meta 开发者_如何学运维charset="utf-8">
    <script>
    $(function() {
        $( "#progressbar" ).progressbar({
            value: 80
        });
    });
    </script>
 <div class="demo">

<div id="progressbar"></div>

</div>


PHP

...
// disable caching
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Expires: Mon, 26 Jul 1991 05:00:00 GMT');  // disable IE caching
header('Content-Type: text/plain; charset=utf-8');

echo progressbar_value;
exit();
...

JS

var refresh_period = 1000; // ms
var script_path = '/script.php';

function updateProgressBar () {
    $.ajax({url: script_path,  success: function (value) {
       $('#progressbar').progressbar(value);
       if (data.value == 100) {
          clearInterval(interval);
       }
    }
}
var interval = setInterval('updateProgressBar()', refresh_period);


You'll need to use AJAX to talk to a PHP file that echos the session var. It can then update the progress bar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜