pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="dtt55pv" 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 中止不會(huì)停止文件上傳

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

            <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="hvxlhn7" id='hNw2e'><tfoot id='hNw2e'></tfoot><dl id='hNw2e'><fieldset id='hNw2e'></fieldset></dl></div>

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

                  本文介紹了XHR 中止不會(huì)停止文件上傳的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我已經(jīng)制作了一個(gè)帶有進(jìn)度條的基于 XHR 的文件上傳器,我想添加一個(gè)功能以在完全上傳之前取消上傳.簡(jiǎn)化的代碼(在 DOM 準(zhǔn)備好后運(yùn)行):

                  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();
                  });
                  

                  在調(diào)用 xhr.abort() 之后,abort 事件處理程序?qū)?'aborted' 打印到控制臺(tái),但它不執(zhí)行任何其他操作.進(jìn)度條沒(méi)有停止,完成后,整個(gè)文件被上傳.在最新的 Firefox 和 Chrome 上測(cè)試.

                  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.

                  我無(wú)法弄清楚我的代碼有什么問(wèn)題.

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

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

                  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();
                  });
                  

                  令我驚訝的是,這按預(yù)期工作.當(dāng) jqXHR.abort() 被調(diào)用時(shí),'aborted' 文本也被打印出來(lái),進(jìn)程停止,只有部分文件被上傳.問(wèn)題是我想讓我的代碼在未來(lái)獨(dú)立于 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 函數(shù).所以解決方案:

                  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(){...});

                  這篇關(guān)于XHR 中止不會(huì)停止文件上傳的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 ajax 調(diào)用完成)
                  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 無(wú)法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)

                    <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="r75t7vx" 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>
                            主站蜘蛛池模板: 不锈钢水箱生产厂家_消防水箱生产厂家-河南联固供水设备有限公司 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 鄂泉泵业官网|(杭州、上海、全国畅销)大流量防汛排涝泵-LW立式排污泵 | 电销卡_稳定企业大语音卡-归属地可选-世纪通信 | 无线遥控更衣吊篮_IC卡更衣吊篮_电动更衣吊篮配件_煤矿更衣吊篮-力得电子 | 全自动过滤器_反冲洗过滤器_自清洗过滤器_量子除垢环_量子环除垢_量子除垢 - 安士睿(北京)过滤设备有限公司 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 光泽度计_测量显微镜_苏州压力仪_苏州扭力板手维修-苏州日升精密仪器有限公司 | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | ALC墙板_ALC轻质隔墙板_隔音防火墙板_轻质隔墙材料-湖北博悦佳 | 商标转让-商标注册-商标查询-软著专利服务平台 - 赣江万网 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 济南宣传册设计-画册设计_济南莫都品牌设计公司 | 电动手术床,医用护理床,led手术无影灯-曲阜明辉医疗设备有限公司 | 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | 橡胶粉碎机_橡胶磨粉机_轮胎粉碎机_轮胎磨粉机-河南鼎聚重工机械制造有限公司 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | 沈阳激光机-沈阳喷码机-沈阳光纤激光打标机-沈阳co2激光打标机 | 精密五金加工厂-CNC数控车床加工_冲压件|蜗杆|螺杆加工「新锦泰」 | 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 铝扣板-铝方通-铝格栅-铝条扣板-铝单板幕墙-佳得利吊顶天花厂家 elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 亚克隆,RNAi干扰检测,miRNA定量检测-上海基屹生物科技有限公司 | 湖南自考_湖南自学考试网 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 裹包机|裹膜机|缠膜机|绕膜机-上海晏陵智能设备有限公司 | 济南电缆桥架|山东桥架-济南航丰实业有限公司 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 | 达利园物流科技集团-| 有源电力滤波装置-电力有源滤波器-低压穿排电流互感器|安科瑞 | 裹包机|裹膜机|缠膜机|绕膜机-上海晏陵智能设备有限公司 | 宝元数控系统|对刀仪厂家|东莞机器人控制系统|东莞安川伺服-【鑫天驰智能科技】 | 烽火安全网_加密软件、神盾软件官网| 气胀轴|气涨轴|安全夹头|安全卡盘|伺服纠偏系统厂家-天机传动 | 上海深蓝_缠绕机_缠膜机-上海深蓝机械装备有限公司 | 纸箱抗压机,拉力机,脂肪测定仪,定氮仪-山东德瑞克仪器有限公司 | 集菌仪_智能集菌仪_全封闭集菌仪_无菌检查集菌仪厂家-那艾 |