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

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

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

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

        猴子補丁 XMLHTTPRequest.onreadystatechange

        Monkey patch XMLHTTPRequest.onreadystatechange(猴子補丁 XMLHTTPRequest.onreadystatechange)
          <tbody id='4GAqW'></tbody>
          <tfoot id='4GAqW'></tfoot>
        1. <small id='4GAqW'></small><noframes id='4GAqW'>

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

                <legend id='4GAqW'><style id='4GAqW'><dir id='4GAqW'><q id='4GAqW'></q></dir></style></legend>

                  本文介紹了猴子補丁 XMLHTTPRequest.onreadystatechange的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  猴子如何修補 XMLHTTPRequestonreadystatechange 函數.我正在嘗試添加一個函數,當從頁面發出的每個 ajax 請求都返回時將調用該函數.

                  How would go about monkey patching the XMLHTTPRequest's onreadystatechange function. I'm trying to add a function that would be called when every ajax request made from a page come back.

                  我知道這聽起來很糟糕,但用例卻很奇特.我想將某個 SDK 與控制臺 (jqconsole) 一起使用,但在控制臺中顯示 ajax 調用的狀態和結果,而無需修改外部 SDK.

                  I know this sounds like a terrible idea, but the use case is quite peculiar. I want to use a certain SDK with a console (jqconsole) but show status and results from ajax calls within the console without modifying the external SDK.

                  我查看了 這篇文章,其中包含大量信息,但沒有任何內容猴子修補回調似乎超出了我的 JavaScript 技能.

                  I've looked at this post which had great info, but nothing on monkey patching the callback which seem to exceed my JavaScript skills.

                  P.S 不能使用 jQuery,因為它只支持由 jQuery 而不是直接來自 XMLHTTPRequests 的 ajax 調用,這里就是這種情況.

                  P.S Can't use jQuery since it only supports ajax calls made from jQuery not from XMLHTTPRequests directly which is the case here.

                  推薦答案

                  要猴子補丁XMLHttpRequest,你需要知道一個AJAX請求一般是如何構造的:

                  To monkey-patch XMLHttpRequests, you need to know how an AJAX request is generally constructed:

                  1. 構造函數調用
                  2. 準備請求(setRequestHeader(), open())
                  3. 發送請求(.send).

                  通用補丁

                  (function(xhr) {
                      function banana(xhrInstance) { // Example
                          console.log('Monkey RS: ' + xhrInstance.readyState);
                      }
                      // Capture request before any network activity occurs:
                      var send = xhr.send;
                      xhr.send = function(data) {
                          var rsc = this.onreadystatechange;
                          if (rsc) {
                              // "onreadystatechange" exists. Monkey-patch it
                              this.onreadystatechange = function() {
                                  banana(this);
                                  return rsc.apply(this, arguments);
                              };
                          }
                          return send.apply(this, arguments);
                      };
                  })(XMLHttpRequest.prototype);
                  

                  前面假設 onreadystatechange 已分配給 onreadystatechange 處理程序.為簡單起見,我沒有包含 其他事件的代碼,例如加載.另外,我沒有考慮使用 addEventListener 添加的事件.

                  The previous assumed that onreadystatechange was assigned to the onreadystatechange handler. For simplicity, I didn't include the code for other events, such as onload. Also, I did not account for events added using addEventListener.

                  之前的補丁針對所有請求運行.但是,如果您只想將補丁限制為特定請求怎么辦?具有特定 URL 或異步標志和特定請求正文的請求?

                  The previous patch runs for all requests. But what if you want to limit the patch to a specific request only? A request with a certain URL or async flag and a specific request body?

                  示例:攔截所有請求正文中包含TEST"的POST請求

                  Example: Intercepting all POST requests whose request body contains "TEST"

                  (function(xhr) {
                      function banana(xhrInstance) { // Example
                          console.log('Monkey RS: ' + xhrInstance.readyState);
                      }
                      // 
                      var open = xhr.open;
                      xhr.open = function(method, url, async) {
                          // Test if method is POST
                          if (/^POST$/i.test(method)) {
                              var send = this.send;
                              this.send = function(data) {
                                  // Test if request body contains "TEST"
                                  if (typeof data === 'string' && data.indexOf('TEST') >= 0) {
                                      var rsc = this.onreadystatechange;
                                      if (rsc) {
                                          // Apply monkey-patch
                                          this.onreadystatechange = function() {
                                              banana(this);
                                              return rsc.apply(this, arguments);
                                          };
                                      }
                                  }
                                  return send.apply(this, arguments);
                              };
                          }
                          return open.apply(this, arguments);
                      };
                  })(XMLHttpRequest.prototype);
                  

                  使用的主要技術是透明重寫使用...

                  The main techniques used is the transparent rewrite using...

                  var original = xhr.method; 
                  xhr.method = function(){
                      /*...*/;
                      return original.apply(this, arguments);
                  };
                  

                  我的示例非常基本,可以擴展以滿足您的確切愿望.不過,這取決于您.

                  My examples are very basic, and can be extended to meet your exact wishes. That's up to you, however.

                  這篇關于猴子補丁 XMLHTTPRequest.onreadystatechange的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='acrh7'></tbody>
                    1. <i id='acrh7'><tr id='acrh7'><dt id='acrh7'><q id='acrh7'><span id='acrh7'><b id='acrh7'><form id='acrh7'><ins id='acrh7'></ins><ul id='acrh7'></ul><sub id='acrh7'></sub></form><legend id='acrh7'></legend><bdo id='acrh7'><pre id='acrh7'><center id='acrh7'></center></pre></bdo></b><th id='acrh7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='acrh7'><tfoot id='acrh7'></tfoot><dl id='acrh7'><fieldset id='acrh7'></fieldset></dl></div>

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

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

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

                            <tfoot id='acrh7'></tfoot>
                            主站蜘蛛池模板: 精品一区二区国产 | 激情婷婷| www.日韩 | 性久久久久久久 | 黄色免费网站视频 | 国产精品欧美在线 | 国产一区在线视频 | 久久精品2 | 日本一本在线 | 久久久久国产视频 | 亚洲精品视频在线播放 | 成人免费视频一区二区 | 国产小视频在线观看 | 一区二区三区国产精品 | 欧美日韩一二区 | 黄色片91 | 狠狠草视频 | 4虎最新网址 | 国产寡妇亲子伦一区二区三区四区 | 激情视频小说 | 国产在线成人 | 日韩在线中文 | 日韩精品少妇 | 天天爽夜夜爽夜夜爽精品视频 | 国产又猛又黄又爽 | 国产精品成人一区二区三区 | 亚洲成人高清 | 一级毛片在线看 | 成人免费在线播放 | 国产精品国产三级国产aⅴ浪潮 | 在线va | 在线视频福利 | 欧美狠狠操 | 久久精品网 | 国产精品美女久久久久av爽 | 亚洲激情在线观看 | 十八岁毛片 | 高清一级片 | 国产一级在线观看 | 欧美精品一级片 | 久久99精品久久久久久琪琪 |