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

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

      <bdo id='l15dY'></bdo><ul id='l15dY'></ul>

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

    1. <legend id='l15dY'><style id='l15dY'><dir id='l15dY'><q id='l15dY'></q></dir></style></legend>
        <tfoot id='l15dY'></tfoot>

        XHR 中止不會停止文件上傳

        XHR abort doesn#39;t stop file uploading(XHR 中止不會停止文件上傳)

            <tbody id='hNw2e'></tbody>

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

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

                  本文介紹了XHR 中止不會停止文件上傳的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我已經制作了一個帶有進度條的基于 XHR 的文件上傳器,我想添加一個功能以在完全上傳之前取消上傳.簡化的代碼(在 DOM 準備好后運行):

                  I've made an XHR-based file uploader with progressbar, and I would like to add a feature to cancel the upload before it fully uploaded. The simlified code (runs after DOM ready):

                  var xhr;
                  
                  $('#upload').click(function(){
                      var file = $('#file').get(0).files[0];
                      xhr = new XMLHttpRequest();
                      xhr.upload.onprogress = function(event){
                          if (event.lengthComputable){
                              var percent = event.loaded / event.total;
                              $('#uploadpercent').html(Math.round(percent * 100) + "%");
                          }
                      };
                      xhr.abort = function(){
                          console.log('aborted');
                      };
                      xhr.onload = function(){
                          $('#uploadpercent').html("100%");
                          // ...
                      };
                      xhr.open("POST", "upload.php?filename=" + file.name);
                      xhr.send(file);
                  });
                  
                  $('#cancel').click(function(){
                      xhr.abort();
                  });
                  

                  在調用 xhr.abort() 之后,abort 事件處理程序將 'aborted' 打印到控制臺,但它不執行任何其他操作.進度條沒有停止,完成后,整個文件被上傳.在最新的 Firefox 和 Chrome 上測試.

                  After the xhr.abort() called, the abort event handler prints the 'aborted' to the console, but it doesn't do anything else. The progress bar doesn't stop, and after it finished, the entire file is uploaded. Tested on the latest Firefox and Chrome.

                  我無法弄清楚我的代碼有什么問題.

                  I can't figure out what is wrong with my code.

                  我用 jQuery 也試過了,代碼:(主要來自 如何異步上傳文件?)

                  I've tried the same with jQuery, the code: (mostly from How can I upload files asynchronously?)

                  var jqXHR;
                  
                  $('#upload').click(function(){
                      var file = $('#file').get(0).files[0];
                      jqXHR = $.ajax({
                          type : "POST",
                          url : "upload.php?filename=" + file.name,
                          data : file,
                          xhr: function(){
                              var myXhr = $.ajaxSettings.xhr();
                              if (myXhr.upload){
                                  myXhr.upload.addEventListener('progress', function(event){
                                      if (event.lengthComputable){
                                          var percent = event.loaded / event.total;
                                          $('#uploadpercent').html(Math.round(percent * 100) + "%");
                                      }
                                  }, false);
                              }
                              return myXhr;
                          },
                          success : function(response){
                              $('#uploadpercent').html("100%");
                              if (response.length > 0){
                                  console.log(response);
                              }
                          },
                          error : function(_jqXHR, textStatus){
                              if (textStatus === "abort"){
                                  console.log('aborted');
                              }
                          },
                          cache : false,
                          contentType : false,
                          processData : false
                      });
                  });
                  
                  $('#cancel').click(function(){
                      jqXHR.abort();
                  });
                  

                  令我驚訝的是,這按預期工作.當 jqXHR.abort() 被調用時,'aborted' 文本也被打印出來,進程停止,只有部分文件被上傳.問題是我想讓我的代碼在未來獨立于 jquery,但我還不明白為什么我的代碼不能以同樣的方式工作.

                  To my surprise, this is working as expected. When the jqXHR.abort() called, the 'aborted' text also printed, the process stopped, and only part of the file have been uploaded. The problem is I want to make my code independent of jquery in the future, and I don't understand yet why my code isn't working the same way.

                  推薦答案

                  好的,我注意到事件名稱是 onabort.使用 xhr.abort = ... 行,我覆蓋了 abort 函數.所以解決方案:

                  Ok, I noticed that the event name is onabort. With the xhr.abort = ... line I overwrote the abort function. So the solution:

                  xhr.onabort = function(){...};

                  xhr.addEventListener("abort", function(){...});

                  這篇關于XHR 中止不會停止文件上傳的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

                    <tbody id='IPBbO'></tbody>

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

                    <tfoot id='IPBbO'></tfoot>
                        1. <legend id='IPBbO'><style id='IPBbO'><dir id='IPBbO'><q id='IPBbO'></q></dir></style></legend>
                        2. <small id='IPBbO'></small><noframes id='IPBbO'>

                            <bdo id='IPBbO'></bdo><ul id='IPBbO'></ul>
                            主站蜘蛛池模板: 国产中文原创 | 91不卡| 亚洲成av人影片在线观看 | 国产精品99久久久久久大便 | 国产高清在线视频 | 蜜桃综合在线 | 亚洲欧美网 | 国产成人福利在线观看 | 精品国产一区二区三区性色 | 人妖videosex高潮另类 | 国产精品一区在线播放 | 精品中文字幕一区 | 中文字幕视频在线 | 亚洲日韩中文字幕一区 | 韩日视频在线观看 | 日本不卡高清视频 | 欧美一级黄带 | 日韩精品极品视频在线观看免费 | 91传媒在线观看 | 日韩国产高清在线观看 | 在线观看免费av网站 | 亚洲视频免费 | 成人国产在线观看 | 色综合99 | 91精品国产乱码久久久久久久久 | 日韩精品人成在线播放 | 一级毛片,一级毛片 | 中文字幕 在线观看 | 久久久久成人精品亚洲国产 | 精品一区二区三区在线观看 | 国产97色 | 国产精品福利一区二区三区 | 国产精品视频一区二区三区 | 久久国产免费 | 成人福利在线 | 一区在线免费视频 | 成人av一区二区在线观看 | 麻豆av网站 | 免费成人高清在线视频 | 妞干网视频 | 一区二区三区欧美 |