zoukankan      html  css  js  c++  java
  • 文件上传显示进度(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
  • 相关阅读:
    201141 live the lie until the lie becomes your life
    my php & mysql FAQ
    suger日料财务
    python 应用thrift thrift的监控fb303
    cherryPy学习
    my linux FAQ
    Javascript无阻塞加载方法
    设计模式学习笔记之组合模式模式
    【转】cookie
    C# 多线程
  • 原文地址:https://www.cnblogs.com/licunzhi/p/9087174.html
Copyright © 2011-2022 走看看