监听上传文件进度条

来源:互联网 发布:淘宝药品货到付款 8.1 编辑:程序博客网 时间:2024/06/06 18:44
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中可以或得到上传进度数据
})
})

原创粉丝点击