如何使用jquery / javascript跟踪下载百分比? [英] How to track the download percentage using jquery/javascript?
问题描述
我想在我的页面中有一个进度条,其中包含一个下载操作。在文件上传是可能的,但在下载也有可能吗?你可以给我一些很好的参考吗?
I want to have a progress bar in my page that has an action of DOWNLOAD. In file upload it is possible but in download is it possible also? Can you give me some good reference for this?
我找不到任何好的参考。
I can't find any good reference for this.
推荐答案
尝试这样: LINK
Try this: LINK
堆栈流QN 链接
这部分代码基本上为进度条所需的值提供百分位数的功能。
This part of the code basically provides the percentile functionality for the value you need for the progress bar.
// progress on transfers from the server to the client (downloads)
function updateProgress (oEvent) {
if (oEvent.lengthComputable) {
var percentComplete = oEvent.loaded / oEvent.total;
// ...
} else {
// Unable to compute progress information since the total size is unknown
}
}
XMLHttpRequest 提供了侦听正在处理请求时可能发生的各种事件的能力。这包括定期进度通知,错误通知等。
XMLHttpRequest provides the ability to listen to various events that can occur while the request is being processed. This includes periodic progress notifications, error notifications, and so forth.
这篇关于如何使用jquery / javascript跟踪下载百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!