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

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

        获取 JQuery ajax 请求进度的最干净的方法是什么

        时间:2023-10-14

        <small id='7ZdhX'></small><noframes id='7ZdhX'>

        <tfoot id='7ZdhX'></tfoot>

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

            <bdo id='7ZdhX'></bdo><ul id='7ZdhX'></ul>
                  本文介绍了获取 JQuery ajax 请求进度的最干净的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在普通的javascript中非常简单:只需要​​将回调附加到{XMLHTTPRequest}.onprogress

                  In plain javascript is very simple: need just to attach the callback to {XMLHTTPRequest}.onprogress

                  var xhr = new XMLHttpRequest();
                  
                  xhr.onprogress = function(e){
                      if (e.lengthComputable)
                          var percent = (e.loaded / e.total) * 100;
                  };
                  
                  xhr.open('GET', 'http://www...', true);
                  xhr.onreadystatechange = function() {
                      ...
                  };
                  xhr.send(null);
                  

                  但我正在做一个 ajax 站点,它使用 JQuery($.get()$.ajax())下载 html 数据,我想知道哪个是获取请求进度的最佳方法是用一点进度条显示它,但奇怪的是,我在 JQuery 文档中找不到任何有用的东西......

                  but I'm doing an ajax site that download html data with JQuery ($.get() or $.ajax()) and I was wondering which is the best way to get the progress of a request in order to display it with a little progress bar but curiously, I'm not finding anything usefull in JQuery documentation...

                  推荐答案

                  类似这样的 $.ajax (虽然只有 HTML5):

                  Something like this for $.ajax (HTML5 only though):

                  $.ajax({
                      xhr: function() {
                          var xhr = new window.XMLHttpRequest();
                          xhr.upload.addEventListener("progress", function(evt) {
                              if (evt.lengthComputable) {
                                  var percentComplete = evt.loaded / evt.total;
                                  //Do something with upload progress here
                              }
                         }, false);
                  
                         xhr.addEventListener("progress", function(evt) {
                             if (evt.lengthComputable) {
                                 var percentComplete = evt.loaded / evt.total;
                                 //Do something with download progress
                             }
                         }, false);
                  
                         return xhr;
                      },
                      type: 'POST',
                      url: "/",
                      data: {},
                      success: function(data){
                          //Do something on success
                      }
                  });
                  

                  这篇关于获取 JQuery ajax 请求进度的最干净的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:AngularJS 错误:跨源请求仅支持协议方案:http、dat 下一篇:防止 Xmlhttprequest 的重定向

                  相关文章

                  最新文章

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

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

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

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

                      <tfoot id='nDdpE'></tfoot>