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

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

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

        <bdo id='b3R3B'></bdo><ul id='b3R3B'></ul>
      <tfoot id='b3R3B'></tfoot>
    1. <i id='b3R3B'><tr id='b3R3B'><dt id='b3R3B'><q id='b3R3B'><span id='b3R3B'><b id='b3R3B'><form id='b3R3B'><ins id='b3R3B'></ins><ul id='b3R3B'></ul><sub id='b3R3B'></sub></form><legend id='b3R3B'></legend><bdo id='b3R3B'><pre id='b3R3B'><center id='b3R3B'></center></pre></bdo></b><th id='b3R3B'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='b3R3B'><tfoot id='b3R3B'></tfoot><dl id='b3R3B'><fieldset id='b3R3B'></fieldset></dl></div>
    2. 攔截 XMLHttpRequest 并修改 responseText

      Intercept XMLHttpRequest and modify responseText(攔截 XMLHttpRequest 并修改 responseText)
            <bdo id='gwQjs'></bdo><ul id='gwQjs'></ul>
          • <i id='gwQjs'><tr id='gwQjs'><dt id='gwQjs'><q id='gwQjs'><span id='gwQjs'><b id='gwQjs'><form id='gwQjs'><ins id='gwQjs'></ins><ul id='gwQjs'></ul><sub id='gwQjs'></sub></form><legend id='gwQjs'></legend><bdo id='gwQjs'><pre id='gwQjs'><center id='gwQjs'></center></pre></bdo></b><th id='gwQjs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gwQjs'><tfoot id='gwQjs'></tfoot><dl id='gwQjs'><fieldset id='gwQjs'></fieldset></dl></div>

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

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

                <tfoot id='gwQjs'></tfoot>

                  <tbody id='gwQjs'></tbody>
                本文介紹了攔截 XMLHttpRequest 并修改 responseText的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試構建一個腳本,它將充當本機 XMLHttpRequest 對象的代理/包裝器,使我能夠攔截它、修改 responseText 并返回到原始的 onreadystatechange 事件.

                I'm trying to build a script that will act as a proxy/wrapper for the native XMLHttpRequest object enabling me to intercept it, modify the responseText and return back to the original onreadystatechange event.

                上下文是,如果應用程序嘗試接收的數據已經在本地存儲中可用,則中止 XMLHttpRequest 并將本地存儲的數據傳遞回應用程序的成功/失敗回調方法.假設我無法控制應用現有的 AJAX 回調方法.

                The context being, if the data the app is trying to receive is already available in local storage, to abort the XMLHttpRequest and pass the locally stored data back into the apps success/failure callback methods. Assume I have no control over the apps existing AJAX callback methods.

                我最初嘗試了以下想法..

                I had originally tried the following idea..

                var send = XMLHttpRequest.prototype.send;
                XMLHttpRequest.prototype.send = function(data){
                   //Do some stuff in here to modify the responseText
                   send.call(this, data);
                };
                

                但正如我現在所建立的,responseText 是只讀的.

                But as I have now established, the responseText is read only.

                然后我嘗試退后一步,為 XMLHttpRequest 編寫我自己的完整本機代理,最終編寫了我自己的本機方法版本.類似于這里討論的...

                I then tried taking a step back, writing my own full native proxy to XMLHttpRequest, ultimately ending up writing my own version of the native methods. Similar to what is discussed here...

                http://www.ilinsky.com/articles/XMLHttpRequest/#implementation-wrapping

                但它很快就變得混亂了,并且仍然很難將修改后的數據返回到原始的 onReadyStateChange 方法中.

                But it rapidly got confusing, and still have the difficulty of returning the modified data back into the original onReadyStateChange method.

                有什么建議嗎?這甚至可能嗎?

                Any suggestions? Is this even possible?

                推薦答案

                //
                // firefox, ie8+ 
                //
                var accessor = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'responseText');
                
                Object.defineProperty(XMLHttpRequest.prototype, 'responseText', {
                	get: function() {
                		console.log('get responseText');
                		return accessor.get.call(this);
                	},
                	set: function(str) {
                		console.log('set responseText: %s', str);
                		//return accessor.set.call(this, str);
                	},
                	configurable: true
                });
                
                
                //
                // chrome, safari (accessor == null)
                //
                var rawOpen = XMLHttpRequest.prototype.open;
                
                XMLHttpRequest.prototype.open = function() {
                	if (!this._hooked) {
                		this._hooked = true;
                		setupHook(this);
                	}
                	rawOpen.apply(this, arguments);
                }
                
                function setupHook(xhr) {
                	function getter() {
                		console.log('get responseText');
                
                		delete xhr.responseText;
                		var ret = xhr.responseText;
                		setup();
                		return ret;
                	}
                
                	function setter(str) {
                		console.log('set responseText: %s', str);
                	}
                
                	function setup() {
                		Object.defineProperty(xhr, 'responseText', {
                			get: getter,
                			set: setter,
                			configurable: true
                		});
                	}
                	setup();
                }

                這篇關于攔截 XMLHttpRequest 并修改 responseText的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 部分內容)

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

                  • <bdo id='jhuFg'></bdo><ul id='jhuFg'></ul>
                        <tfoot id='jhuFg'></tfoot>
                            <tbody id='jhuFg'></tbody>

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

                          主站蜘蛛池模板: 色婷婷亚洲一区二区三区 | 日本大香伊一区二区三区 | 亚洲欧美一区二区三区在线 | xxxxxx国产| 91高清在线观看 | 久久久精品一区二区三区 | 久久久精 | 999热视频 | 免费观看黄色一级片 | 一级毛片在线播放 | 久久久无码精品亚洲日韩按摩 | 国产欧美一区二区三区日本久久久 | 欧美一级片在线观看 | 伦理午夜电影免费观看 | 精品国产一区二区三区久久久蜜月 | www.天天操| 国产 欧美 日韩 一区 | 91看片官网 | 99pao成人国产永久免费视频 | 精品日韩在线 | 在线观看涩涩视频 | 亚洲免费视频一区 | 黄色精品 | 国产精品精品视频一区二区三区 | 视频一区二区在线观看 | 在线观看欧美一区 | 视频一区二区中文字幕 | 一区二区在线看 | 国产第一页在线观看 | 黄色毛片一级 | 精品国产乱码久久久久久中文 | 一区中文字幕 | 欧美中文一区 | 亚洲精品乱码久久久久久久久久 | 久久综合九色综合欧美狠狠 | 欧美日韩福利视频 | 中文字幕一区二区三区四区五区 | 瑟瑟激情 | 成人在线一区二区三区 | 久久久久高清 | 午夜影视在线观看 |