pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

                問題描述

                我正在嘗試構(gòu)建一個(gè)腳本,它將充當(dāng)本機(jī) XMLHttpRequest 對(duì)象的代理/包裝器,使我能夠攔截它、修改 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.

                上下文是,如果應(yīng)用程序嘗試接收的數(shù)據(jù)已經(jīng)在本地存儲(chǔ)中可用,則中止 XMLHttpRequest 并將本地存儲(chǔ)的數(shù)據(jù)傳遞回應(yīng)用程序的成功/失敗回調(diào)方法.假設(shè)我無法控制應(yīng)用現(xiàn)有的 AJAX 回調(diào)方法.

                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);
                };
                

                但正如我現(xiàn)在所建立的,responseText 是只讀的.

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

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

                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

                但它很快就變得混亂了,并且仍然很難將修改后的數(shù)據(jù)返回到原始的 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();
                }

                這篇關(guān)于攔截 XMLHttpRequest 并修改 responseText的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 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 無法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)

                  <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="o8ptsyt" 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'>

                          主站蜘蛛池模板: 武汉创亿电气设备有限公司_电力检测设备生产厂家 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 祝融环境-地源热泵多恒系统高新技术企业,舒适生活环境缔造者! | 东莞市超赞电子科技有限公司 全系列直插/贴片铝电解电容,电解电容,电容器 | 酒精检测棒,数显温湿度计,酒安酒精测试仪,酒精检测仪,呼气式酒精检测仪-郑州欧诺仪器有限公司 | 杰福伦_磁致伸缩位移传感器_线性位移传感器-意大利GEFRAN杰福伦-河南赉威液压科技有限公司 | 东莞画册设计_logo/vi设计_品牌包装设计 - 华略品牌设计公司 | 地源热泵一体机,地源热泵厂家-淄博汇能环保设备有限公司 | 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 | 中央空调维修、中央空调保养、螺杆压缩机维修-苏州东菱空调 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | 氧化锆陶瓷_氧化锆陶瓷加工_氧化锆陶瓷生产厂家-康柏工业陶瓷有限公司 | 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | 东莞螺丝|东莞螺丝厂|东莞不锈钢螺丝|东莞组合螺丝|东莞精密螺丝厂家-东莞利浩五金专业紧固件厂家 | 北京成考网-北京成人高考网 | 航空障碍灯_高中低光强航空障碍灯_民航许可认证航空警示灯厂家-东莞市天翔航天科技有限公司 | 集装箱展厅-住人集装箱住宿|建筑|房屋|集装箱售楼处-山东锐嘉科技工程有限公司 | 锂电池砂磨机|石墨烯砂磨机|碳纳米管砂磨机-常州市奥能达机械设备有限公司 | 细沙回收机-尾矿干排脱水筛设备-泥石分离机-建筑垃圾分拣机厂家-青州冠诚重工机械有限公司 | 多物理场仿真软件_电磁仿真软件_EDA多物理场仿真软件 - 裕兴木兰 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | AGV无人叉车_激光叉车AGV_仓储AGV小车_AGV无人搬运车-南昌IKV机器人有限公司[官网] | 精密交叉滚子轴承厂家,转盘轴承,YRT转台轴承-洛阳千协轴承 | 电梯装饰-北京万达中意电梯装饰有限公司 | 罗氏牛血清白蛋白,罗氏己糖激酶-上海嵘崴达实业有限公司 | 气动隔膜泵厂家-温州永嘉定远泵阀有限公司 | TPE_TPE热塑性弹性体_TPE原料价格_TPE材料厂家-惠州市中塑王塑胶制品公司- 中塑王塑胶制品有限公司 | 武汉高温老化房,恒温恒湿试验箱,冷热冲击试验箱-武汉安德信检测设备有限公司 | 冷却塔降噪隔音_冷却塔噪声治理_冷却塔噪音处理厂家-广东康明冷却塔降噪厂家 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 | 真空吸污车_高压清洗车厂家-程力专用汽车股份有限公司官网 | CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 中药二氧化硫测定仪,食品二氧化硫测定仪|俊腾百科 | 荣事达手推洗地机_洗地机厂家_驾驶式扫地机_工业清洁设备 | 胶原检测试剂盒,弹性蛋白检测试剂盒,类克ELISA试剂盒,阿达木单抗ELISA试剂盒-北京群晓科苑生物技术有限公司 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 |