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

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

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

        如何通過 XHR onProgress 函數使用壓縮/壓縮的內容

        How can I use deflated/gzipped content with an XHR onProgress function?(如何通過 XHR onProgress 函數使用壓縮/壓縮的內容?)
        <tfoot id='HXFcn'></tfoot>
          <tbody id='HXFcn'></tbody>
        • <i id='HXFcn'><tr id='HXFcn'><dt id='HXFcn'><q id='HXFcn'><span id='HXFcn'><b id='HXFcn'><form id='HXFcn'><ins id='HXFcn'></ins><ul id='HXFcn'></ul><sub id='HXFcn'></sub></form><legend id='HXFcn'></legend><bdo id='HXFcn'><pre id='HXFcn'><center id='HXFcn'></center></pre></bdo></b><th id='HXFcn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HXFcn'><tfoot id='HXFcn'></tfoot><dl id='HXFcn'><fieldset id='HXFcn'></fieldset></dl></div>
            <bdo id='HXFcn'></bdo><ul id='HXFcn'></ul>

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

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

                  本文介紹了如何通過 XHR onProgress 函數使用壓縮/壓縮的內容?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我之前看到過很多與此類似的問題,但我還沒有找到一個準確描述我當前問題的問題,所以這里是:

                  我有一個通過 AJAX 加載大型(0.5 到 10 MB 之間)JSON 文檔的頁面,以便客戶端代碼可以處理它.加載文件后,我不會遇到任何我沒想到的問題.但是,下載需要很長時間,所以我嘗試利用

                  這些是相關的 request 標頭,表明請求是 AJAX 并且 Accept-Encoding 設置正確:

                  GET/dashboard/reports/ajax/load HTTP/1.1連接:保持活動緩存控制:無緩存Pragma:無緩存接受:應用程序/json、文本/javascript、*/*;q=0.01X-Requested-With: XMLHttpRequest用戶代理:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.99 Safari/537.22接受編碼:gzip、deflate、sdch接受語言:en-US,en;q=0.8接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.3

                  這些是相關的 response 標頭,表明 Content-LengthContent-Type 設置正確:

                  HTTP/1.1 200 OK緩存控制:無存儲、無緩存、必須重新驗證、后檢查 = 0、預檢查 = 0內容編碼:放氣內容類型:應用程序/json日期:格林威治標準時間 2013 年 2 月 26 日星期二 18:59:07到期:1981 年 11 月 19 日星期四 08:52:00 GMTP3P: CP="CAO PSA OUR"Pragma:無緩存服務器:Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.4.7X-Powered-By: PHP/5.4.7內容長度:223879連接:保持活動

                  對于它的價值,我在標準 (http) 和安全 (https) 連接上都試過了,沒有任何區別:內容在瀏覽器中加載正常,但沒有被 Progress API 處理.

                  <小時>

                  根據 Adam 的建議,我嘗試將服務器端切換為 gzip 編碼,但沒有成功或更改.以下是相關的響應標頭:

                  HTTP/1.1 200 OK緩存控制:無存儲、無緩存、必須重新驗證、后檢查 = 0、預檢查 = 0內容編碼:gzip內容類型:應用程序/json日期:格林威治標準時間 2013 年 3 月 4 日星期一 22:33:19到期:1981 年 11 月 19 日星期四 08:52:00 GMTP3P: CP="CAO PSA OUR"Pragma:無緩存服務器:Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.4.7X-Powered-By: PHP/5.4.7內容長度:28250連接:保持活動

                  重復一遍:內容正在被正確下載和解碼,這只是我遇到問題的進度 API.

                  <小時>

                  根據 Bertrand 的請求,請求如下:

                  $.ajax({url: '<截斷的網址>',數據: {},成功:onDone,數據類型:'json',緩存:真,進度:onProgress ||功能(){}});

                  這是我正在使用的 onProgress 事件處理程序(這不是太瘋狂):

                  函數(jqXHR, evt){//是的,我知道這有時會產生無窮大var pct = 100 * evt.position/evt.total;//只是一個更新一些樣式和javascript的方法更新進度(pct);});

                  解決方案

                  我無法解決在壓縮內容本身上使用 onProgress 的問題,但我想出了這個半簡單的解決方法.簡而言之:在發送GET請求的同時向服務器發送HEAD請求,一旦有足夠的信息就渲染進度條這樣做.

                  <小時>

                  函數加載器(onDone, onProgress, url, data){//onDone = 成功下載時運行的事件處理程序//onProgress = 在下載期間運行的事件處理程序//url = 要加載的 url//data = 與 AJAX 請求一起發送的額外參數var content_length = null;self.meta_xhr = $.ajax({網址:網址,數據:數據,數據類型:'json',類型:'頭',成功:函數(數據、狀態、jqXHR){content_length = jqXHR.getResponseHeader("X-Content-Length");}});self.xhr = $.ajax({網址:網址,數據:數據,成功:onDone,數據類型:'json',進度:函數(jqXHR,evt){var pct = 0;如果(evt.lengthComputable){pct = 100 * evt.position/evt.total;}否則 if (self.content_length != null){pct = 100 * evt.position/self.content_length;}onProgress(pct);}});}

                  然后使用它:

                  loader(函數(響應){console.log("內容已加載!立即執行.");},函數(pct){console.log("內容為" + pct + "%已加載.");},'<這里的網址>', {});

                  <小時>

                  在服務器端,在 GETHEAD 請求上設置 X-Content-Length 標頭(應該代表未壓縮內容長度),并中止發送 HEAD 請求中的內容.

                  在 PHP 中,設置標頭如下所示:

                  header("X-Content-Length: ".strlen($payload));

                  如果是 HEAD 請求,則中止發送內容:

                  if ($_SERVER['REQUEST_METHOD'] == "HEAD"){出口;}

                  <小時>

                  下面是實際效果:

                  HEAD 在下面的截圖中需要這么長時間的原因是服務器仍然需要解析文件才能知道它有多長,但這是我絕對可以改進的,而且絕對是比原來有所改進.

                  I've seen a bunch of similar questions to this get asked before, but I haven't found one that describes my current problem exactly, so here goes:

                  I have a page which loads a large (between 0.5 and 10 MB) JSON document via AJAX so that the client-side code can process it. Once the file is loaded, I don't have any problems that I don't expect. However, it takes a long time to download, so I tried leveraging the XHR Progress API to render a progress bar to indicate to the user that the document is loading. This worked well.

                  Then, in an effort to speed things up, I tried compressing the output on the server side via gzip and deflate. This worked too, with tremendous gains, however, my progress bar stopped working.

                  I've looked into the issue for a while and found that if a proper Content-Length header isn't sent with the requested AJAX resource, the onProgress event handler cannot function as intended because it doesn't know how far along in the download it is. When this happens, a property called lengthComputable is set to false on the event object.

                  This made sense, so I tried setting the header explicitly with both the uncompressed and the compressed length of the output. I can verify that the header is being sent, and I can verify that my browser knows how to decompress the content. But the onProgress handler still reports lengthComputable = false.

                  So my question is: is there a way to gzipped/deflated content with the AJAX Progress API? And if so, what am I doing wrong right now?


                  This is how the resource appears in the Chrome Network panel, showing that compression is working:

                  These are the relevant request headers, showing that the request is AJAX and that Accept-Encoding is set properly:

                  GET /dashboard/reports/ajax/load HTTP/1.1
                  Connection: keep-alive
                  Cache-Control: no-cache
                  Pragma: no-cache
                  Accept: application/json, text/javascript, */*; q=0.01
                  X-Requested-With: XMLHttpRequest
                  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.99 Safari/537.22
                  Accept-Encoding: gzip,deflate,sdch
                  Accept-Language: en-US,en;q=0.8
                  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
                  

                  These are the relevant response headers, showing that the Content-Length and Content-Type are being set correctly:

                  HTTP/1.1 200 OK
                  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
                  Content-Encoding: deflate
                  Content-Type: application/json
                  Date: Tue, 26 Feb 2013 18:59:07 GMT
                  Expires: Thu, 19 Nov 1981 08:52:00 GMT
                  P3P: CP="CAO PSA OUR"
                  Pragma: no-cache
                  Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.4.7
                  X-Powered-By: PHP/5.4.7
                  Content-Length: 223879
                  Connection: keep-alive
                  

                  For what it's worth, I've tried this on both a standard (http) and secure (https) connection, with no differences: the content loads fine in the browser, but isn't processed by the Progress API.


                  Per Adam's suggestion, I tried switching the server side to gzip encoding with no success or change. Here are the relevant response headers:

                  HTTP/1.1 200 OK
                  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
                  Content-Encoding: gzip
                  Content-Type: application/json
                  Date: Mon, 04 Mar 2013 22:33:19 GMT
                  Expires: Thu, 19 Nov 1981 08:52:00 GMT
                  P3P: CP="CAO PSA OUR"
                  Pragma: no-cache
                  Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.4.7
                  X-Powered-By: PHP/5.4.7
                  Content-Length: 28250
                  Connection: keep-alive
                  

                  Just to repeat: the content is being downloaded and decoded properly, it's just the progress API that I'm having trouble with.


                  Per Bertrand's request, here's the request:

                  $.ajax({
                      url: '<url snipped>',
                      data: {},
                      success: onDone,
                      dataType: 'json',
                      cache: true,
                      progress: onProgress || function(){}
                  });
                  

                  And here's the onProgress event handler I'm using (it's not too crazy):

                  function(jqXHR, evt)
                  {
                      // yes, I know this generates Infinity sometimes
                      var pct = 100 * evt.position / evt.total;
                  
                      // just a method that updates some styles and javascript
                      updateProgress(pct);
                  });
                  

                  解決方案

                  I wasn't able to solve the issue of using onProgress on the compressed content itself, but I came up with this semi-simple workaround. In a nutshell: send a HEAD request to the server at the same time as a GET request, and render the progress bar once there's enough information to do so.


                  function loader(onDone, onProgress, url, data)
                  {
                      // onDone = event handler to run on successful download
                      // onProgress = event handler to run during a download
                      // url = url to load
                      // data = extra parameters to be sent with the AJAX request
                      var content_length = null;
                  
                      self.meta_xhr = $.ajax({
                          url: url,
                          data: data,
                          dataType: 'json',
                          type: 'HEAD',
                          success: function(data, status, jqXHR)
                          {
                              content_length = jqXHR.getResponseHeader("X-Content-Length");
                          }
                      });
                  
                      self.xhr = $.ajax({
                          url: url,
                          data: data,
                          success: onDone,
                          dataType: 'json',
                          progress: function(jqXHR, evt)
                          {
                              var pct = 0;
                              if (evt.lengthComputable)
                              {
                                  pct = 100 * evt.position / evt.total;
                              }
                              else if (self.content_length != null)
                              {
                                  pct = 100 * evt.position / self.content_length;
                              }
                  
                              onProgress(pct);
                          }
                      });
                  }
                  

                  And then to use it:

                  loader(function(response)
                  {
                      console.log("Content loaded! do stuff now.");
                  },
                  function(pct)
                  {
                      console.log("The content is " + pct + "% loaded.");
                  },
                  '<url here>', {});
                  


                  On the server side, set the X-Content-Length header on both the GET and the HEAD requests (which should represent the uncompressed content length), and abort sending the content on the HEAD request.

                  In PHP, setting the header looks like:

                  header("X-Content-Length: ".strlen($payload));
                  

                  And then abort sending the content if it's a HEAD request:

                  if ($_SERVER['REQUEST_METHOD'] == "HEAD")
                  {
                      exit;
                  }
                  


                  Here's what it looks like in action:

                  The reason the HEAD takes so long in the below screenshot is because the server still has to parse the file to know how long it is, but that's something I can definitely improve on, and it's definitely an improvement from where it was.

                  這篇關于如何通過 XHR onProgress 函數使用壓縮/壓縮的內容?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='SVTce'></tbody>
                    • <bdo id='SVTce'></bdo><ul id='SVTce'></ul>
                    • <tfoot id='SVTce'></tfoot>

                      1. <small id='SVTce'></small><noframes id='SVTce'>

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

                          • 主站蜘蛛池模板: 麻豆av一区二区三区久久 | 91精品国产乱码久久蜜臀 | 99视频网站 | 精品成人佐山爱一区二区 | 亚洲国产精品久久久久婷婷老年 | 天堂亚洲| 99久久99久久精品国产片果冰 | 亚洲一区中文 | 精品视频在线免费观看 | 国产精品久久久久久久7电影 | 久久久综合久久 | 国产乱码精品一区二区三区中文 | 久久亚洲一区二区三区四区 | 欧美精品一区二区三区在线播放 | www.99re| 国产精品久久免费观看 | 日韩精品久久久 | 日韩国产高清在线观看 | 国产在线精品区 | 亚洲精品乱码久久久久久久久 | 九九成人 | 国产欧美视频一区 | 伊人99| 精品久久国产老人久久综合 | 国产高清久久 | 中文字幕在线网 | 99reav| 色婷婷一区二区三区四区 | 成人一区二区三区在线观看 | 国产精品免费一区二区三区四区 | 亚洲成人免费av | 欧美日韩在线一区二区 | 国产精品一区二区三区在线 | 9色视频在线 | 人人叉 | 91精品国产综合久久婷婷香蕉 | 五月婷婷激情网 | 亚洲狠狠爱 | 色资源在线观看 | 新疆少妇videos高潮 | 91精品国产91久久久久久三级 |