• 文件上传显示进度(js代码实现,不适合多次中转显示)


    $.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
  • 相关阅读:
    12-转盘
    11-UIView与核心动画对比
    10-动画组
    09-转场动画
    08-图片抖动(帧动画)
    07-心跳效果
    06-CABasicAnimation基础核心动画
    05-时钟效果
    计时器延迟 NSTimer和CADisplaylink GCD中的延迟
    ScrollView与UIPageController
  • 原文地址:https://www.cnblogs.com/licunzhi/p/9087174.html
Copyright © 2020-2023  润新知