使用 jQuery progressBar 做文件上传的进度条指示

来源:互联网 发布:linux 根目录read only 编辑:程序博客网 时间:2024/05/16 06:25
http://www.oschina.net/code/snippet_12_1313var progress_key = '4cd0f29463edb'; // this sets up the progress bar$(document).ready(function() {    $("#uploadprogressbar").progressBar();}); // fades in the progress bar and starts polling the upload progress after 1.5secondsfunction beginUpload() {    // uses ajax to poll the uploadprogress.php page with the id    // deserializes the json string, and computes the percentage (integer)    // update the jQuery progress bar    // sets a timer for the next poll in 750ms    $("#uploadprogressbar").fadeIn();     var i = setInterval(function() {         $.getJSON("demo.php?id=" + progress_key, function(data) {            if (data == null) {                clearInterval(i);                location.reload(true);                return;            }             var percentage = Math.floor(100 * parseInt(data.bytes_uploaded) / parseInt(data.bytes_total));            $("#uploadprogressbar").progressBar(percentage);        });    }, 1500);}

原创粉丝点击