$.ajax({
???url : basePath + "/container"+"/upload"+"?_t="+new Date().getTime(),
???dataType : ‘json‘,
???data : form,
???type : ‘POST‘,
???processData : false, // 告诉jQuery不要去处理发送的数据
???contentType : false,
???xhr: function(){
???????myXhr = $.ajaxSettings.xhr();
???????if(myXhr.upload){
???????????myXhr.upload.addEventListener(‘progress‘,function(e) {
???????????????if (e.lengthComputable) {
???????????????????var percent = Math.floor(e.loaded/e.total*100);
???????????????????if(percent <= 100) {
???????????????????????// $("#J_progress_bar").progress(‘set progress‘, percent);
???????????????????????// $("#J_progress_label").html(‘已上传:‘+percent+‘%‘);
???????????????????????console.log(percent)
???????????????????}
???????????????????if(percent >= 100) {
???????????????????????// $("#J_progress_label").html(‘文件上传完毕,请等待...‘);
???????????????????????// $("#J_progress_label").addClass(‘success‘);
???????????????????????console.log(percent)
???????????????????}
???????????????}
???????????}, false);
???????}
???????return myXhr;
???},
???success: function(res){
???????// 请求成功
???},
???error: function(res) {
???????// 请求失败
???????console.log(res);
???}
??
})
显示时时上传进度,data参数为formData ???formData的具体使用可以自行查询资料
欢迎加群交流:589780530
文件上传显示进度(js代码实现,不适合多次中转显示)
原文地址:https://www.cnblogs.com/licunzhi/p/9087174.html