开发者

How to fill a jQuery progress bar from a value of text file which is changing?

开发者 https://www.devze.com 2023-01-29 14:48 出处:网络
I have this progress bar and I need to make the 开发者_运维技巧value depending on a value which I read from a text file. This value changes by time and thus the filling of the bar should change accord

I have this progress bar and I need to make the 开发者_运维技巧value depending on a value which I read from a text file. This value changes by time and thus the filling of the bar should change according to that. Here is the code:

<!-- Demo Progressbar --> 
<meta charset="utf-8">
    <script>
    $(function() {
        $( "#progressbar" ).progressbar({
            value: 80 //which need to be dynamic
        });
    });
    </script>
 <div class="demo">

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

</div>
<!-- End demo -->


You can read the value of the text file using jQuery's ajax: http://api.jquery.com/jQuery.ajax/

After you get this value, you can supply it to the progress bar.

EXAMPLE [the contents of "TextFile1" should be just a plain number like "88"]:

$(document).ready(function () {
    $.ajax({
        url: "TextFile1.txt",
        type: "GET",
        success: function (value) {
            $("#progressbar").progressbar({
                value: value
            });
        }
    });
});

NOTE: this will only work if the text file is in the project directory and can be hit by URL [http://demo/TextFile1.txt]. If it's somewhere else in the file system, you will have to use server-side code (.NET, PHP) to read the value, and then call the server-side code using jQuery's ajax.

0

精彩评论

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