久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='ovu0n'><style id='ovu0n'><dir id='ovu0n'><q id='ovu0n'></q></dir></style></legend>

      <bdo id='ovu0n'></bdo><ul id='ovu0n'></ul>
    <i id='ovu0n'><tr id='ovu0n'><dt id='ovu0n'><q id='ovu0n'><span id='ovu0n'><b id='ovu0n'><form id='ovu0n'><ins id='ovu0n'></ins><ul id='ovu0n'></ul><sub id='ovu0n'></sub></form><legend id='ovu0n'></legend><bdo id='ovu0n'><pre id='ovu0n'><center id='ovu0n'></center></pre></bdo></b><th id='ovu0n'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ovu0n'><tfoot id='ovu0n'></tfoot><dl id='ovu0n'><fieldset id='ovu0n'></fieldset></dl></div>
    <tfoot id='ovu0n'></tfoot>
  • <small id='ovu0n'></small><noframes id='ovu0n'>

        使用 XMLHttpRequest 上傳大文件時的進度條

        Progress bar while uploading large files with XMLHttpRequest(使用 XMLHttpRequest 上傳大文件時的進度條)

            • <small id='sftgY'></small><noframes id='sftgY'>

              • <bdo id='sftgY'></bdo><ul id='sftgY'></ul>
                <i id='sftgY'><tr id='sftgY'><dt id='sftgY'><q id='sftgY'><span id='sftgY'><b id='sftgY'><form id='sftgY'><ins id='sftgY'></ins><ul id='sftgY'></ul><sub id='sftgY'></sub></form><legend id='sftgY'></legend><bdo id='sftgY'><pre id='sftgY'><center id='sftgY'></center></pre></bdo></b><th id='sftgY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sftgY'><tfoot id='sftgY'></tfoot><dl id='sftgY'><fieldset id='sftgY'></fieldset></dl></div>
                <tfoot id='sftgY'></tfoot>

                    <tbody id='sftgY'></tbody>
                1. <legend id='sftgY'><style id='sftgY'><dir id='sftgY'><q id='sftgY'></q></dir></style></legend>
                2. 本文介紹了使用 XMLHttpRequest 上傳大文件時的進度條的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 XMLHttpRequest 和 file.slice 將一些大文件上傳到服務器.
                  我已經在文檔和其他各種鏈接的幫助下做到了這一點.
                  由于上傳大文件是一項漫長的工作,我想為用戶提供一個進度條.
                  經過更多閱讀后,我遇到了 示例,理論上,正是我需要的.
                  通過獲取示例代碼并使其適應我的需求,我達到了

                  I am trying to upload some large files to the server using XMLHttpRequest and file.slice.
                  I've manage doing this with the help of documentations and other various links.
                  Since uploading large file is a lengthily job, i would like to provide the user with a progress bar.
                  After some more readings i've come across on an example that, theoretically, does exactly what i need.
                  By taking the sample code and adapting it to my needs i reached

                  var upload =
                  {
                  blobs: [],
                  pageName: '',
                  bytesPerChunk: 20 * 1024 * 1024,
                  currentChunk: 0,
                  loaded: 0,
                  total: 0,
                  file: null,
                  fileName: "",
                  
                  uploadChunk: function (blob, fileName, fileType) {
                      var xhr = new XMLHttpRequest();
                  
                      xhr.onreadystatechange = function () {
                          if (xhr.readyState == 4) {
                              if (xhr.responseText) {
                                  // alert(xhr.responseText);
                              }
                          }
                      };
                  
                      xhr.addEventListener("load", function (evt) {
                          $("#dvProgressPrcent").html("100%");
                          $get('dvProgress').style.width = '100%';
                      }, false);
                  
                      xhr.addEventListener("progress", function (evt) {
                          if (evt.lengthComputable) {
                              var progress = Math.ceil(((upload.loaded + evt.loaded) / upload.total) * 100);
                              $("#dvProgressPrcent").html(progress + "%");
                              $get('dvProgress').style.width = progress + '%';
                          }
                      }, false);
                  
                      xhr.upload.addEventListener("progress", function (evt) {
                          if (evt.lengthComputable) {
                              var progress = Math.ceil(((upload.loaded + evt.loaded) / upload.total) * 100);
                              $("#dvProgressPrcent").html(progress + "%");
                              $get('dvProgress').style.width = progress + '%';
                          }
                      }, false);
                  
                      xhr.open('POST', upload.pageName, false);
                  
                      xhr.setRequestHeader("Content-Type", "multipart/form-data");
                      xhr.setRequestHeader("X-File-Name", fileName);
                      xhr.setRequestHeader("X-File-Type", fileType);
                      xhr.send(blob);
                  },
                  upload: function (file) {
                      var start = 0;
                      var end = 0;
                      var size = file.size;
                  
                      var date = new Date();
                      upload.fileName = date.format("dd.MM.yyyy_HH.mm.ss") + "_" + file.name;
                  
                      upload.loaded = 0;
                      upload.total = file.size;
                  
                      while (start < size) {
                          end = start + upload.bytesPerChunk;
                          if (end > size) {
                              end = size;
                          }
                  
                          var blob = file.slice(start, end);
                          upload.uploadChunk(blob, upload.fileName, file.type);
                          start = end;
                          upload.loaded += start;
                      }
                  
                      return upload.fileName;
                  }
                  };
                  

                  電話就像(沒有驗證)

                  upload.upload(document.getElementById("#upload").files[0]);
                  

                  我的問題是進度事件沒有觸發.
                  我已經為進度事件嘗試了 xhr.addEventListener 和 xhr.upload.addEventListener (一次和一次),但它永遠不會觸發.onreadystatechange 和 load 事件觸發就好了.

                  My problem is that the progress event doesn't trigger.
                  I've tried xhr.addEventListener and with xhr.upload.addEventListener (each at a time and both at a time) for the progress event but it never triggers. The onreadystatechange and load events trigger just fine.

                  如果我做錯了什么,我將不勝感激

                  I would greatly appreciate help with what i am doing wrong

                  更新
                  經過多次嘗試,我設法模擬了一個進度,但我遇到了另一個問題:Chrome 的 UI 在上傳期間沒有更新.
                  現在的代碼是這樣的

                  Update
                  After many attempts i've manage to simulate a progress but i've ran into another problem: Chrome's UI is not updating during the upload.
                  The code looks like this now

                  var upload =
                  {
                      pageName: '',
                      bytesPerChunk: 20 * 1024 * 1024,
                      loaded: 0,
                      total: 0,
                      file: null,
                      fileName: "",
                  
                      uploadFile: function () {
                          var size = upload.file.size;
                  
                          if (upload.loaded > size) return;
                  
                          var end = upload.loaded + upload.bytesPerChunk;
                          if (end > size) { end = size; }
                  
                          var blob = upload.file.slice(upload.loaded, end);
                  
                          var xhr = new XMLHttpRequest();
                  
                          xhr.open('POST', upload.pageName, false);
                  
                          xhr.setRequestHeader("Content-Type", "multipart/form-data");
                          xhr.setRequestHeader("X-File-Name", upload.fileName);
                          xhr.setRequestHeader("X-File-Type", upload.file.type);
                  
                          xhr.send(blob);
                  
                          upload.loaded += upload.bytesPerChunk;
                  
                          setTimeout(upload.updateProgress, 100);
                          setTimeout(upload.uploadFile, 100);
                      },
                      upload: function (file) {
                          upload.file = file;
                  
                          var date = new Date();
                          upload.fileName = date.format("dd.MM.yyyy_HH.mm.ss") + "_" + file.name;
                  
                          upload.loaded = 0;
                          upload.total = file.size;
                  
                          setTimeout(upload.uploadFile, 100);
                  
                  
                          return upload.fileName;
                      },
                      updateProgress: function () {
                          var progress = Math.ceil(((upload.loaded) / upload.total) * 100);
                          if (progress > 100) progress = 100;
                  
                          $("#dvProgressPrcent").html(progress + "%");
                          $get('dvProgress').style.width = progress + '%';
                      }
                  };
                  


                  更新 2
                  我已經設法修復它并模擬了一個也適用于 chrome 的進度條.
                  我已經用有效的代碼示例更新了之前的代碼示例.
                  您可以通過減小一次上傳的塊的大小來更頻繁地刷新"欄謝謝你的幫助


                  Update 2
                  I've managed to fix it and simulate a progress bar that works in chrome too.
                  i've updated previous code sample with the one that works.
                  You can make the bar 'refresh' more often by reducing the size of the chunk uploaded at a time Tahnk you for your help

                  推薦答案

                  如 https://stackoverflow.com/a/中所述3694435/460368,你可以這樣做:

                  if(xhr.upload)
                       xhr.upload.onprogress=upload.updateProgress;
                  

                  updateProgress: function updateProgress(evt) 
                  {
                     if (evt.lengthComputable) {
                         var progress = Math.ceil(((upload.loaded + evt.loaded) / upload.total) * 100);
                         $("#dvProgressPrcent").html(progress + "%");
                         $get('dvProgress').style.width = progress + '%';
                     }
                  }
                  

                  這篇關于使用 XMLHttpRequest 上傳大文件時的進度條的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)

                      <small id='FL0Wt'></small><noframes id='FL0Wt'>

                      <i id='FL0Wt'><tr id='FL0Wt'><dt id='FL0Wt'><q id='FL0Wt'><span id='FL0Wt'><b id='FL0Wt'><form id='FL0Wt'><ins id='FL0Wt'></ins><ul id='FL0Wt'></ul><sub id='FL0Wt'></sub></form><legend id='FL0Wt'></legend><bdo id='FL0Wt'><pre id='FL0Wt'><center id='FL0Wt'></center></pre></bdo></b><th id='FL0Wt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FL0Wt'><tfoot id='FL0Wt'></tfoot><dl id='FL0Wt'><fieldset id='FL0Wt'></fieldset></dl></div>

                          <tbody id='FL0Wt'></tbody>
                      • <tfoot id='FL0Wt'></tfoot>

                          <legend id='FL0Wt'><style id='FL0Wt'><dir id='FL0Wt'><q id='FL0Wt'></q></dir></style></legend>
                            <bdo id='FL0Wt'></bdo><ul id='FL0Wt'></ul>
                          • 主站蜘蛛池模板: 99福利视频 | 欧美久久国产 | 久久久久久亚洲精品 | 一区二区三区在线播放 | 久久精品国产清自在天天线 | 九色在线 | 欧美久久久 | 亚洲一区二区三区免费视频 | 久久99精品久久久久久国产越南 | 亚洲h在线观看 | 欧美一区二区成人 | 午夜免费视频 | 亚洲精品一区中文字幕乱码 | 日日骚视频 | 国产精品日韩欧美一区二区三区 | 一级免费黄色 | 国产精品久久久久久网站 | 免费观看一级特黄欧美大片 | 人人干人人干人人干 | 国产精品久久久久久久7电影 | 国产精品v | 九九精品在线 | 欧美一区二区三区视频在线播放 | 久久久99国产精品免费 | 三级av免费 | 全免费a级毛片免费看视频免 | 欧美日韩不卡合集视频 | 亚洲视频www | 91免费在线 | 欧美一区二区三区免费在线观看 | 91精品国产手机 | 欧美色999| sese视频在线观看 | 欧美激情欧美激情在线五月 | 91xh98hx 在线 国产 | 日韩精品一区二区三区视频播放 | 精品一区免费 | 久久亚洲欧美日韩精品专区 | 国产一级毛片视频 | 啪一啪在线视频 | 亚洲日本乱码在线观看 |