【问题标题】:How to get percentage uploading file with Ajax?如何使用 Ajax 获取上传文件的百分比?
【发布时间】:2014-12-16 04:34:53
【问题描述】:
我在 Twitter 引导程序中使用 Ajax 和进度条来上传文件功能。但我不知道如何使用 Ajax 获取上传文件的百分比。请帮忙,谢谢。
【问题讨论】:
标签:
javascript
php
ajax
twitter-bootstrap
zend-framework2
【解决方案1】:
您可以使用一个 jQuery 文件上传插件。它允许您调用进度函数。插件的 Git 在这里:GitHub Repo。几周前我发现this tutorial 出于同样的原因使用该插件,这是一个部分示例。
progress: function(e, data) {
// Calculate the completion percentage of the upload
var progress = parseInt(data.loaded / data.total * 100, 10);
// Update the hidden input field and trigger a change
// so that the jQuery knob plugin knows to update the dial
data.context.find('input').val(progress).change();
if(progress == 100) {
data.context.removeClass('working');
}
}