js文件上传添加进度条

 

<div id = "progress_1"  class="systemUpdates_box dialogArea" style="display:none;">
             <div class="progressBar_box " id="progressBar">
                 <div class="barContent_box" id="barContent"></div>
             </div>
              <div class="bottomDisplay_box">
                <p class="operationTips" style="margin-top: 1em;color: #ff6600;margin:0 auto;width: 40%;" id="operationTips3">提示语</p>
                 <div class="progress_box">
                     <label id="progressShow">0%</label>
                 </div>
             </div> 
         </div>
.systemUpdates_box {
    width:780px;
    height:200px;
    background:#eeeeee;
    padding-top:55px;
    padding-left:50px;
}
.newSystem_box {
    color:#5e5454;
    font-size:28px;
    font-weight:bold;
}
.tips_box {
    font-size:8px;
}
.progressBar_box {
    margin-top:30px;
    width:720px;
    height:8px;
    background:#ffffff;
    border-radius:5px;
}
.barContent_box {
    height: 8px;
    background: #f96600;
    border-radius: 5px;
}
.bottomDisplay_box {
    width: 720px;
    height: 100px;
    margin-top: 18px;
}
.cancelButton_box {
    width: 110px;
    height: 40px;
    background: #ffffff;
    border: none;
    border-radius: 50px;
    font-weight: bold;
    outline: none;
}
.cancelButton_box:hover {
        color: white;
        background: #343238;
    }
.progress_box {
    width:20px;
    margin: 5px auto;
    font-size:large;
}

 

function progressBar(evt) {
    var loaded = evt.loaded; //已经上传大小情况
    var tot = evt.total; //附件总大小
    var per = Math.floor(100 * loaded / tot); //已经上传的百分比
    console.log(per);
    $("#progress_1").show();  //显示进度条
    testBegin(per);           //显示百分比
}

function setAjaxJsonDataupdata(urlstr, reqJson, callback, options) {
    
    $.ajax({
        url: urlstr,
        async: true,
        // timeout: 6000,
        cache: false,
        type: "POST",
        //dataType: "json",
        data: reqJson,
        contentType: "application/octet-stream",
        processData: false,
        error: function(xhr, textStatus) {
            var errorInfo = textStatus + ": " + xhr.status + " " + xhr.readyState;
            console.log(errorInfo);
        },
        xhr: function() { //ajax进度条
            var xhr = $.ajaxSettings.xhr();
            if(xhr.onprogress){
                xhr.onprogress = progressBar;
            }
            else if (xhr.upload) {
                xhr.upload.addEventListener("progress", progressBar, false);
            }
            return xhr;
        },
       //  success: function(data){
       //      var obj = data2Object(data);
       //      if (typeof callback === "function"){
       //          callback(obj);
       //      }
       //  }
        success: function(data){    
            callback(data);
        }
    });

function testBegin(val) {
    var progressBar = document.getElementById("progressBar");
    var barContent = document.getElementById("barContent");
    var label = document.getElementById("progressShow");
    barContent.style.width = progressBar.offsetWidth * (val / 100) + "px";
    label.innerText = ((val) + "%");

} 

setAjaxJsonDataupdata("action/uploadfile", name, function(obj){
            $("#progress_1").hide();
            upgradeStep = 3;
            setFirmwareStep(upgradeStep);
            console.log("set_wifi_param success!!!");
            console.log(obj);
        }, {
            async: false
        });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值