<small id='5RBMJ'></small><noframes id='5RBMJ'>

    1. <i id='5RBMJ'><tr id='5RBMJ'><dt id='5RBMJ'><q id='5RBMJ'><span id='5RBMJ'><b id='5RBMJ'><form id='5RBMJ'><ins id='5RBMJ'></ins><ul id='5RBMJ'></ul><sub id='5RBMJ'></sub></form><legend id='5RBMJ'></legend><bdo id='5RBMJ'><pre id='5RBMJ'><center id='5RBMJ'></center></pre></bdo></b><th id='5RBMJ'></th></span></q></dt></tr></i><div id='5RBMJ'><tfoot id='5RBMJ'></tfoot><dl id='5RBMJ'><fieldset id='5RBMJ'></fieldset></dl></div>
      <tfoot id='5RBMJ'></tfoot>

        <bdo id='5RBMJ'></bdo><ul id='5RBMJ'></ul>
        <legend id='5RBMJ'><style id='5RBMJ'><dir id='5RBMJ'><q id='5RBMJ'></q></dir></style></legend>
      1. Ajax - 下载前获取文件大小

        Ajax - Get size of file before downloading(Ajax - 下载前获取文件大小)
        <tfoot id='NH4O0'></tfoot>
        <i id='NH4O0'><tr id='NH4O0'><dt id='NH4O0'><q id='NH4O0'><span id='NH4O0'><b id='NH4O0'><form id='NH4O0'><ins id='NH4O0'></ins><ul id='NH4O0'></ul><sub id='NH4O0'></sub></form><legend id='NH4O0'></legend><bdo id='NH4O0'><pre id='NH4O0'><center id='NH4O0'></center></pre></bdo></b><th id='NH4O0'></th></span></q></dt></tr></i><div id='NH4O0'><tfoot id='NH4O0'></tfoot><dl id='NH4O0'><fieldset id='NH4O0'></fieldset></dl></div>

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

              <tbody id='NH4O0'></tbody>
          • <legend id='NH4O0'><style id='NH4O0'><dir id='NH4O0'><q id='NH4O0'></q></dir></style></legend>

                  <bdo id='NH4O0'></bdo><ul id='NH4O0'></ul>
                  本文介绍了Ajax - 下载前获取文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  基本上,我想根据文件大小确定是否应该使用 AJAX 下载文件.

                  Basically, I want to figure out whether I should download a file using AJAX, depending on how large the filesize is.

                  我想这个问题也可以改写为:如何只获取 ajax 请求的标头?

                  I guess this question could also be rephrased as: How do I get only the header of an ajax request?

                  编辑:ultima-rat0 在评论中告诉我两个问题已经被问过了,显然和这个一样.它们非常相似,但它们都想要 jQuery.我想要一个非 jQuery 解决方案.

                  EDIT: ultima-rat0 in the comments told me of two questions that had already been asked that apparently are the same as this one. They are very similar, but they both want jQuery. I want a non-jQuery solution to this.

                  推荐答案

                  可以手动获取XHR响应头数据:

                  You can get XHR response header data manually:

                  http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-方法

                  此函数将获取请求的 URL 的文件大小:

                  This function will get the filesize of the requested URL:

                  function get_filesize(url, callback) {
                      var xhr = new XMLHttpRequest();
                      xhr.open("HEAD", url, true); // Notice "HEAD" instead of "GET",
                                                   //  to get only the header
                      xhr.onreadystatechange = function() {
                          if (this.readyState == this.DONE) {
                              callback(parseInt(xhr.getResponseHeader("Content-Length")));
                          }
                      };
                      xhr.send();
                  }
                  
                  get_filesize("http://example.com/foo.exe", function(size) {
                      alert("The size of foo.exe is: " + size + " bytes.");
                  });
                  

                  这篇关于Ajax - 下载前获取文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                  How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                  Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                  What is quot;X-Content-Type-Options=nosniffquot;?(什么是“X-Content-Type-Options=nosniff?)
                  SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                  Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)

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

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

                        <tbody id='rrIdK'></tbody>

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

                      • <tfoot id='rrIdK'></tfoot>
                          <bdo id='rrIdK'></bdo><ul id='rrIdK'></ul>