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

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

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

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

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

    3. <tfoot id='yPfI1'></tfoot>

      1. 重新創建 jQuery 的 ajaxStart 和 ajaxComplete 功能

        Recreating jQuery#39;s ajaxStart and ajaxComplete functionality(重新創建 jQuery 的 ajaxStart 和 ajaxComplete 功能)
        • <bdo id='XtBN5'></bdo><ul id='XtBN5'></ul>

          <tfoot id='XtBN5'></tfoot>

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

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

                    <tbody id='XtBN5'></tbody>
                1. <i id='XtBN5'><tr id='XtBN5'><dt id='XtBN5'><q id='XtBN5'><span id='XtBN5'><b id='XtBN5'><form id='XtBN5'><ins id='XtBN5'></ins><ul id='XtBN5'></ul><sub id='XtBN5'></sub></form><legend id='XtBN5'></legend><bdo id='XtBN5'><pre id='XtBN5'><center id='XtBN5'></center></pre></bdo></b><th id='XtBN5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XtBN5'><tfoot id='XtBN5'></tfoot><dl id='XtBN5'><fieldset id='XtBN5'></fieldset></dl></div>
                  本文介紹了重新創建 jQuery 的 ajaxStart 和 ajaxComplete 功能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試重現 jQuery 的函數 ajaxComplete 和 ajaxStart 沒有 jQuery,因此它們可以在沒有庫依賴的任何環境中使用(這是一個特殊的用例).這些函數允許在任何 ajax 請求之前和之后調用事件偵聽器.在我的示例中,我稱它們為 preAjaxListener 和 postAjaxListener.

                  I'm trying to reproduce jQuery's functions ajaxComplete and ajaxStart without jQuery so that they could be used in any environment with no library dependencies (it's a special use case). These functions allow for an event listener to be called before and after any ajax request. In my example, I call them preAjaxListener and postAjaxListener.

                  我試圖通過連接到 XMLHttpRequest 對象并覆蓋/裝飾 opensend 來完成它.是的,我知道這很臟.

                  I'm trying to accomplish it by hooking into the XMLHttpRequest object and overwriting/decorating open and send. Yes, I know this is dirty.

                  XMLHttpRequest.prototype.open = (function(orig){
                      return function(a,b,c){
                          this._HREF = b; // store target url
                          return orig.apply(this, arguments); // call original 'open' function
                      };
                  })(XMLHttpRequest.prototype.open);
                  
                  XMLHttpRequest.prototype.send = (function(orig){
                      return function(){
                          var xhr = this;
                          _core._fireAjaxEvents('pre', xhr._HREF); // preAjaxListener fires
                  
                          var rsc = xhr.onreadystatechange || function(){}; // store the original onreadystatechange if it exists
                          xhr.onreadystatechange = function(){ // overwrite with custom function
                              try {
                                  if (xhr.readyState == 4){
                                      _core._fireAjaxEvents('post', xhr._HREF); // postAjaxListneer should fire
                                      this.onreadystatechange = rsc;
                                  } 
                              } catch (e){ }
                              return rsc.apply(this, arguments); // call original readystatechange function
                          };
                  
                          return orig.apply(this, arguments); // call original 'send' function
                      };
                  })(XMLHttpRequest.prototype.send);
                  

                  我不想編寫包裝函數來發出 ajax 請求.我希望能夠掛鉤頁面上任何庫(或使用 vanilla js)發出的任何 ajax 請求.

                  I do not want to write wrapper functions to make ajax requests. I want to be able to hook into any ajax request made by any library (or with vanilla js) on the page.

                  到目前為止,只有 preAjaxListener 函數有效.我似乎無法弄清楚為什么,但似乎 onreadystatechange 從未被調用過.任何指導將不勝感激.

                  So far, only the preAjaxListener function works. I can't seem to figure out why, but it seems that onreadystatechange is never being called. Any guidance would be greatly appreciated.

                  工作演示:http://jsfiddle.net/_nderscore/QTQ5s/

                  推薦答案

                  使用 .onreadystatechange 不起作用,因為我正在使用 jQuery 進行測試,并且 jQuery 的 ajax 方法操作并刪除了 onreadystatechange屬性.

                  Using .onreadystatechange wasn't working because I was testing with jQuery and jQuery's ajax methods manipulate and removes the onreadystatechange property.

                  但是,為 loadend 添加事件偵聽器在除 IE 之外的任何地方都可以正常工作.對于 IE,我設置了一個間隔 - 不是最佳解決方案,但它可以滿足我的需要.我只打算讓這個腳本在 IE8+ 和現代瀏覽器上運行.

                  However, adding an event listener for loadend works just fine everywhere but IE. For IE, I set up an interval instead - not the optimal solution, but it works for my needs. I only intended this script to work on IE8+ and modern browsers.

                  XMLHttpRequest.prototype.send = (function(orig){
                      return function(){
                          _core._fireAjaxEvents('pre', this._HREF);
                  
                          if (!/MSIE/.test(navigator.userAgent)){
                              this.addEventListener("loadend", function(){
                                  _core._fireAjaxEvents('post', this._HREF);
                              }, false);
                          } else {
                              var xhr = this,
                              waiter = setInterval(function(){
                                  if(xhr.readyState && xhr.readyState == 4){
                                      _core._fireAjaxEvents('post', xhr._HREF);
                                      clearInterval(waiter);
                                  }
                              }, 50);
                          }
                  
                          return orig.apply(this, arguments);
                      };
                  })(XMLHttpRequest.prototype.send);
                  

                  這篇關于重新創建 jQuery 的 ajaxStart 和 ajaxComplete 功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 部分內容)

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

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

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

                          <tbody id='Aa2aI'></tbody>
                        <tfoot id='Aa2aI'></tfoot>

                            <i id='Aa2aI'><tr id='Aa2aI'><dt id='Aa2aI'><q id='Aa2aI'><span id='Aa2aI'><b id='Aa2aI'><form id='Aa2aI'><ins id='Aa2aI'></ins><ul id='Aa2aI'></ul><sub id='Aa2aI'></sub></form><legend id='Aa2aI'></legend><bdo id='Aa2aI'><pre id='Aa2aI'><center id='Aa2aI'></center></pre></bdo></b><th id='Aa2aI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Aa2aI'><tfoot id='Aa2aI'></tfoot><dl id='Aa2aI'><fieldset id='Aa2aI'></fieldset></dl></div>
                            主站蜘蛛池模板: 日韩色在线 | 日本精品一区 | 欧美日一区 | 成人福利影院 | 日本免费一区二区三区视频 | 国产美女自拍视频 | 91国语清晰打电话对白 | 夜夜骑综合| 久久久精品黄色 | 四虎午夜剧场 | 国产乱码精品一品二品 | 黄免费观看 | 久久黄视频| 欧美日韩亚洲国产综合 | 黄色骚片 | 欧洲一区视频 | 亚洲精品电影网在线观看 | 久久这里只有精品首页 | 激情小说综合网 | 性一爱一乱一交一视频 | 女同av亚洲女人天堂 | 久久伊人一区 | 日韩淫片免费看 | 韩日一区二区 | 国产在线视频在线观看 | 国产精品一区二区三区久久 | 亚洲视频一区在线观看 | 激情欧美一区二区三区 | 日韩 欧美 综合 | 欧美一级免费 | 超碰在线亚洲 | 欧美成人免费在线 | 国产精品视频一区二区三区 | 国产精品久久99 | 久久久久国产精品一区二区 | 国产日韩一区二区三区 | jlzzxxxx18hd护士 | 精品欧美乱码久久久久久1区2区 | 国产精品久久亚洲7777 | 日韩一区二区在线观看 | 色综合久久天天综合网 |