首页 > 代码库 > ajax监听上传进度

ajax监听上传进度

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #d8a100 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #596972 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #6b82d9 } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #97a700 } span.s1 { color: #6b82d9 } span.s2 { color: #97a700 } span.s3 { color: #596972 } span.s4 { color: #b58a00 } span.s5 { color: #ff7900 } span.s6 { color: #a5b2b9 } span.s7 { color: #000000 } span.s8 { color: #ad5cff } span.s9 { color: #2eafa9 } span.Apple-tab-span { white-space: pre }</style>

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;

}

};

 

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #596972 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #d8a100 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #a5b2b9 } span.s1 { color: #ad5cff } span.s2 { color: #97a700 } span.s3 { color: #596972 } span.s4 { color: #6b82d9 } span.s5 { color: #b58a00 } span.s6 { color: #3c7400 } span.s7 { color: #000000 } span.Apple-tab-span { white-space: pre }</style>

timeout: 1000 * 60,

xhr: xhrOnProgress(function(e) {

console.log(e)

//这里是监听函数 从e中可以或得到上传进度数据

}),

ajax监听上传进度