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

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

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

        <i id='HYVtI'><tr id='HYVtI'><dt id='HYVtI'><q id='HYVtI'><span id='HYVtI'><b id='HYVtI'><form id='HYVtI'><ins id='HYVtI'></ins><ul id='HYVtI'></ul><sub id='HYVtI'></sub></form><legend id='HYVtI'></legend><bdo id='HYVtI'><pre id='HYVtI'><center id='HYVtI'></center></pre></bdo></b><th id='HYVtI'></th></span></q></dt></tr></i><div id='HYVtI'><tfoot id='HYVtI'></tfoot><dl id='HYVtI'><fieldset id='HYVtI'></fieldset></dl></div>
      1. 自定义 XMLHttpRequest.prototype.open

        时间:2023-10-13

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

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

                <tfoot id='WVrg5'></tfoot>
                • <bdo id='WVrg5'></bdo><ul id='WVrg5'></ul>
                  本文介绍了自定义 XMLHttpRequest.prototype.open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  var open = XMLHttpRequest.prototype.open;
                  
                  XMLHttpRequest.prototype.open = function(method, uri, async, user, pass) {
                      this.addEventListener("readystatechange", function(event) {  
                      if(this.readyState == 4){
                         var self = this;
                         var response = {
                           method: method,
                           uri: uri,
                           responseText: self.responseText
                        };
                        console.log(response);  
                      } else {
                          console.log(this.readyState);
                      }
                      }, false);
                    open.call(this, method, uri, async, user, pass);
                  };
                  

                  我正在尝试在发送 XHR 之前收听它们.$.ajax 方法中类似于 jQuery 的 beforeSend 方法.

                  I am trying to listen for XHR before they are being sent. Something similar to jQuery's beforeSend in the $.ajax method.

                  我的目标是在发送所有 XHR 之前监听它们.我想最接近的方法是检查上面是否 this.readyState === 1?

                  My goal is to listen for all XHR's before they are being sent. I suppose the closest thing would be to check above if this.readyState === 1?

                  上面的代码是否会因为我在 XMLHttpRequest 上使用原型而导致任何 ajax 库(如 jQuery)出现故障?

                  Would the code above cause any ajax libraries like jQuery to malfunction because I use prototype on XMLHttpRequest?

                  推荐答案

                  我正在尝试在发送 XHR 之前监听它们.

                  I am trying to listen for XHR before they are being sent.

                  然后尝试欺骗 send() 方法,而不是 open() 方法.

                  Then try to spoof the send() method, not the open() one.

                  上面的代码是否会因为我在 XMLHttpRequest 上使用原型而导致任何 ajax 库(如 jQuery)出现故障?

                  Would the code above cause any ajax libraries like jQuery to malfunction because I use prototype on XMLHttpRequest?

                  不,不是真的.只是,

                  • 在那些库选择不使用 XMLHttpRequest(尤其是 IE)的情况下它不起作用
                  • …如果浏览器不支持 XMLHttpRequest 对象(或不支持访问或修改其原型),甚至会失败
                  • libs 可能能够通过在你可以之前取消引用函数来解决你的欺骗问题(尽管我不知道有什么常见的 lib)
                  • 您的代码使用固定数量的参数调用本机方法,不确定这是否会影响任何内容,并且它不会重新返回结果(即使我们知道它是 undefined).为 100% 确定,请使用 return open.apply(this, arguments);.
                  • it won't work where those libs choose not to use XMLHttpRequest (particularly IE)
                  • …and even fail if the browser does not support the XMLHttpRequest object (or does not support accessing or modifying its prototype)
                  • libs might be able to work around your spoof by dereferencing the functions before you can (though I don't know any common lib that does)
                  • Your code calls the native method with a fixed number of arguments, not sure if that affects anything, and it does not re-return the result (even if we know it's undefined). To be 100% sure, use return open.apply(this, arguments);.

                  这篇关于自定义 XMLHttpRequest.prototype.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如果 XMLHttpRequest 对象支持 W3C 进度事件,如何检 下一篇:Javascript 同步 XMLHttpRequest 的替代方案(在 Safari 中

                  相关文章

                  最新文章

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

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

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