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

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

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

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

    1. <legend id='hL1ru'><style id='hL1ru'><dir id='hL1ru'><q id='hL1ru'></q></dir></style></legend>
      1. 可以使用 xhrFields 將 onprogress 功能添加到 jQuery.

        Can onprogress functionality be added to jQuery.ajax() by using xhrFields?(可以使用 xhrFields 將 onprogress 功能添加到 jQuery.ajax() 嗎?)

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

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

        2. <legend id='bpIoU'><style id='bpIoU'><dir id='bpIoU'><q id='bpIoU'></q></dir></style></legend>

              • <bdo id='bpIoU'></bdo><ul id='bpIoU'></ul>
                  本文介紹了可以使用 xhrFields 將 onprogress 功能添加到 jQuery.ajax() 嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  這里建議:https://gist.github.com/HenrikJoreteg/2502497,我正在嘗試將 onprogress 功能添加到我的 jQuery.ajax() 文件上傳中.上傳工作正常,并且 onprogress 事件正在觸發(fā),但不像我預(yù)期的那樣 - 不是在某個時間間隔重復(fù)觸發(fā),而是在上傳完成時只觸發(fā)一次.有沒有辦法指定onprogress刷新的頻率?或者,我是否正在嘗試做一些無法做到的事情?這是我的代碼:

                  As suggested here: https://gist.github.com/HenrikJoreteg/2502497, I'm trying to add onprogress functionality to my jQuery.ajax() file upload. The upload works fine, and the onprogress event is firing, but not as I expected--instead of firing repeatedly at some time interval, it's firing only once, when the upload has completed. Is there a way to specify the frequency of onprogress refreshes? Or, am I trying to do something that can't be done? Here's my code:

                      $.ajax(
                      {
                          async: true,
                          contentType: file.type,
                          data: file,
                          dataType: 'xml',
                          processData: false,
                          success: function(xml)
                          {
                              // Do stuff with the returned xml
                          },
                          type: 'post',
                          url: '/fileuploader/' + file.name,
                          xhrFields:
                          {
                              onprogress: function(progress)
                              {
                                  var percentage = Math.floor((progress.total / progress.totalSize) * 100);
                                  console.log('progress', percentage);
                                  if (percentage === 100)
                                  {
                                      console.log('DONE!');
                                  }
                              }
                          }
                      });
                  


                  嗯,已經(jīng)好幾年了.我重新審視了這一點,并使用 GetFree 的答案,將我的代碼更新為以下內(nèi)容:


                  Well, it's been a few years. I revisited this, and using GetFree's answer, I updated my code to the following:

                  $('#file_input').change(function()
                  {
                      var file = this.files[0];
                      $('#upload_button').click(funtion(e)
                      {
                          req = new XMLHttpRequest();
                          req.upload.addEventListener('progress', updateProgress, false);
                          req.addEventListener('load', transferComplete, false);
                          var url  = 'https://my.url'; 
                          req.open('POST', url, true);
                          req.setRequestHeader('Content-Type', myFileType);
                          req.setRequestHeader('Content-Length', myFileLength);
                          req.send(file);
                      });
                  );
                  function updateProgress(e)
                  {
                      var percent = Math.floor(e.loaded / e.total * 100);
                      console.log("percent = " + percent);
                  }
                  function transferComplete(e)
                  {
                      console.log("transfer complete");
                  }
                  

                  我已將 GetFree 的帖子標(biāo)記為已接受的答案.抱歉耽擱了.

                  I have marked GetFree's post as the accepted answer. Sorry for the delay.

                  推薦答案

                  簡答:
                  不,你不能使用 xhrFields 做你想做的事.

                  長答案:

                  XmlHttpRequest 對象中有兩個進度事件:

                  There are two progress events in a XmlHttpRequest object:

                  • 響應(yīng)進度(XmlHttpRequest.onprogress)
                    這是瀏覽器從服務(wù)器下載數(shù)據(jù)的時候.

                  • The response progress (XmlHttpRequest.onprogress)
                    This is when the browser is downloading the data from the server.

                  請求進度 (XmlHttpRequest.upload.onprogress)
                  這是瀏覽器向服務(wù)器發(fā)送數(shù)據(jù)(包括 POST 參數(shù)、cookie 和文件)的時候

                  The request progress (XmlHttpRequest.upload.onprogress)
                  This is when the browser is sending the data to the server (including POST parameters, cookies, and files)

                  在您的代碼中,您使用的是響應(yīng)進度事件,但您需要的是請求進度事件.這就是你的做法:

                  In your code you are using the response progress event, but what you need is the request progress event. This is how you do it:

                  $.ajax({
                      async: true,
                      contentType: file.type,
                      data: file,
                      dataType: 'xml',
                      processData: false,
                      success: function(xml){
                          // Do stuff with the returned xml
                      },
                      type: 'post',
                      url: '/fileuploader/' + file.name,
                      xhr: function(){
                          // get the native XmlHttpRequest object
                          var xhr = $.ajaxSettings.xhr() ;
                          // set the onprogress event handler
                          xhr.upload.onprogress = function(evt){ console.log('progress', evt.loaded/evt.total*100) } ;
                          // set the onload event handler
                          xhr.upload.onload = function(){ console.log('DONE!') } ;
                          // return the customized object
                          return xhr ;
                      }
                  });
                  

                  xhr 選項參數(shù)必須是返回原生 XmlHttpRequest 對象以供 jQuery 使用的函數(shù).

                  The xhr option parameter must be a function that returns a native XmlHttpRequest object for jQuery to use.

                  這篇關(guān)于可以使用 xhrFields 將 onprogress 功能添加到 jQuery.ajax() 嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 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 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                  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 部分內(nèi)容)
                    <tbody id='Ignry'></tbody>
                • <small id='Ignry'></small><noframes id='Ignry'>

                    <legend id='Ignry'><style id='Ignry'><dir id='Ignry'><q id='Ignry'></q></dir></style></legend>

                  1. <i id='Ignry'><tr id='Ignry'><dt id='Ignry'><q id='Ignry'><span id='Ignry'><b id='Ignry'><form id='Ignry'><ins id='Ignry'></ins><ul id='Ignry'></ul><sub id='Ignry'></sub></form><legend id='Ignry'></legend><bdo id='Ignry'><pre id='Ignry'><center id='Ignry'></center></pre></bdo></b><th id='Ignry'></th></span></q></dt></tr></i><div class="o0002ms" id='Ignry'><tfoot id='Ignry'></tfoot><dl id='Ignry'><fieldset id='Ignry'></fieldset></dl></div>
                    • <tfoot id='Ignry'></tfoot>
                            <bdo id='Ignry'></bdo><ul id='Ignry'></ul>
                            主站蜘蛛池模板: 北京网站建设-企业网站建设-建站公司-做网站-北京良言多米网络公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 锂电混合机-新能源混合机-正极材料混料机-高镍,三元材料混料机-负极,包覆混合机-贝尔专业混合混料搅拌机械系统设备厂家 | 沥青车辙成型机-车托式混凝土取芯机-混凝土塑料试模|鑫高仪器 | 净水器代理,净水器招商,净水器加盟-FineSky德国法兹全屋净水 | 混合生育酚_醋酸生育酚粉_琥珀酸生育酚-山东新元素生物科技 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | BOE画框屏-触摸一体机-触控查询一体机-触摸屏一体机价格-厂家直销-触发电子 | 桥架-槽式电缆桥架-镀锌桥架-托盘式桥架 - 上海亮族电缆桥架制造有限公司 | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 锥形螺带干燥机(新型耙式干燥机)百科-常州丰能干燥工程 | 冷藏车-东风吸污车-纯电动环卫车-污水净化车-应急特勤保障车-程力专汽厂家-程力专用汽车股份有限公司销售二十一分公司 | 电磁流量计厂家_涡街流量计厂家_热式气体流量计-青天伟业仪器仪表有限公司 | 美的商用净水器_美的直饮机_一级代理经销商_Midea租赁价格-厂家反渗透滤芯-直饮水批发品牌售后 | 称重传感器,测力传感器,拉压力传感器,压力变送器,扭矩传感器,南京凯基特电气有限公司 | 垃圾压缩设备_垃圾处理设备_智能移动式垃圾压缩设备--山东明莱环保设备有限公司 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | TPE_TPE热塑性弹性体_TPE原料价格_TPE材料厂家-惠州市中塑王塑胶制品公司- 中塑王塑胶制品有限公司 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 护栏打桩机-打桩机厂家-恒新重工 | 自动部分收集器,进口无油隔膜真空泵,SPME固相微萃取头-上海楚定分析仪器有限公司 | 江苏南京多语种翻译-专业翻译公司报价-正规商务翻译机构-南京华彦翻译服务有限公司 | nalgene洗瓶,nalgene量筒,nalgene窄口瓶,nalgene放水口大瓶,浙江省nalgene代理-杭州雷琪实验器材有限公司 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 高低温万能试验机_拉力试验机_拉伸试验机-馥勒仪器科技(上海)有限公司 | 河南中整光饰机械有限公司-抛光机,去毛刺抛光机,精密镜面抛光机,全自动抛光机械设备 | uv固化机-丝印uv机-工业烤箱-五金蚀刻机-分拣输送机 - 保定市丰辉机械设备制造有限公司 | 智能交通网_智能交通系统_ITS_交通监控_卫星导航_智能交通行业 | 聚合氯化铝价格_聚合氯化铝厂家_pac絮凝剂-唐达净水官网 | 食安观察网| 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰| 电液推杆生产厂家|电动推杆|液压推杆-扬州唯升机械有限公司 | 免费个人pos机申请办理-移动pos机刷卡-聚合收款码办理 | 北京京云律师事务所 | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 沈阳激光机-沈阳喷码机-沈阳光纤激光打标机-沈阳co2激光打标机 | 防水套管厂家-柔性防水套管-不锈钢|刚性防水套管-天翔管道 | 固诺家居-全屋定制十大品牌_整体衣柜木门橱柜招商加盟 | 考勤系统_考勤管理系统_网络考勤软件_政企|集团|工厂复杂考勤工时统计排班管理系统_天时考勤 | 行星搅拌机,双行星搅拌机,动力混合机,无锡米克斯行星搅拌机生产厂家 |