久久久久久久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的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  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 調(diào)用的狀態(tài)和結(jié)果,而無需修改外部 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.

                  我查看了 這篇文章,其中包含大量信息,但沒有任何內(nèi)容猴子修補回調(diào)似乎超出了我的 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 調(diào)用,這里就是這種情況.

                  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請求一般是如何構(gòu)造的:

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

                  1. 構(gòu)造函數(shù)調(diào)用
                  2. 準備請求(setRequestHeader(), open())
                  3. 發(fā)送請求(.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);
                  

                  前面假設(shè) 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);
                  

                  使用的主要技術(shù)是透明重寫使用...

                  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.

                  這篇關(guān)于猴子補丁 XMLHTTPRequest.onreadystatechange的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                  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屋-程序員軟件開發(fā)技術(shù)分
                  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 部分內(nèi)容)

                    <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>
                            主站蜘蛛池模板: 天天操天天射天天 | 青青草视频免费观看 | 一区二区在线免费观看 | 羞羞视频在线观看 | 国产精品美女一区二区三区 | 中文字字幕一区二区三区四区五区 | 国产欧美一区二区三区日本久久久 | 91精品久久久久久久久久 | 亚洲综合国产精品 | 在线观看视频一区 | 日韩欧美一区二区三区四区 | 一区二区三区免费 | 国产精品久久久久久久毛片 | 成人高清在线视频 | 亚洲综合国产精品 | 免费观看黄网站 | 欧美日韩在线成人 | 91精品国产色综合久久不卡98口 | 成人免费网站视频 | 一区二区三区四区av | 国产一区二区av | 国产毛片久久久久久久久春天 | 欧美天堂| 91中文字幕在线观看 | 成人免费网站www网站高清 | 亚洲国产成人精品女人久久久野战 | 福利网址| 美日韩免费视频 | 日韩欧美中文字幕在线视频 | 国产一区二区免费 | 欧美a在线 | 精国产品一区二区三区四季综 | 亚洲精品久久久久久国产精华液 | 国产福利91精品 | 伊人影院99 | 在线毛片网 | 国产亚洲一区二区在线观看 | 国产精品一区二区av | 国产乱码精品1区2区3区 | 国产精品99久久久久久久久久久久 | 午夜精品|