您的位置:首页 > 其它

监听上传文件进度条

2017-06-12 17:48 260 查看
var xhrOnProgress = function(fun) {

xhrOnProgress.onprogress = fun; //绑定监听函数

return function() {
var xhr = $.ajaxSettings.xhr();

if (xhrOnProgress.onprogress == null || typeof xhrOnProgress.onprogress === 'undefined')
return xhr;

if (xhrOnProgress.onprogress && xhr.upload) {
xhr.upload.onprogress = xhrOnProgress.onprogress;
}
return xhr;
}
};
$.ajax({
url: url,
type: 'POST',
data: files
timeout: 1000 * 60 ,
xhr: xhrOnProgress(function(e) {
//这里是监听函数 从e中可以或得到上传进度数据
})
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: