多文件上传进度的实现-springmvc

来源:互联网 发布:淘宝交了定金怎么退 编辑:程序博客网 时间:2024/05/05 23:57

 $.ajax({  
       url: "url",  
       type: "POST",  
       data: formData,  
       xhr: function(){ //获取ajaxSettings中的xhr对象,为它的upload属性绑定progress事件的处理函数  
         
           myXhr = $.ajaxSettings.xhr();  
           if(myXhr.upload){ //检查upload属性是否存在  
               //绑定progress事件的回调函数  
              /*  myXhr.upload.addEventListener('progress',progressHandlingFunction, false);   */ 
              myXhr.upload.addEventListener('progress',function(e){
              if (e.lengthComputable) {
             $('#showProgress'+index).attr({value : e.loaded, max : e.total}); //更新数据到进度条  
             var percent = (e.loaded/e.total*100);
             $('#song-progress'+index).html(percent.toFixed(0) + "%");  
            }  
              },false);
           }  
           return myXhr; //xhr对象返回给jQuery使用  
       },  
       success: function(result){ 
           if(result==true)  $("#song-file-span"+index).text("已上传"); 
       },  
       contentType: false, //必须false才会自动加上正确的Content-Type  
       processData: false  //必须false才会避开jQuery对 formdata 的默认处理  
   });  
}


index 代表上传的那个文件对象

0 0
原创粉丝点击