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

    <small id='4f3OA'></small><noframes id='4f3OA'>

      • <bdo id='4f3OA'></bdo><ul id='4f3OA'></ul>

      <tfoot id='4f3OA'></tfoot>

      Javascript:覆盖 XMLHttpRequest.open()

      时间:2023-10-15

          <tbody id='hycPd'></tbody>

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

                <bdo id='hycPd'></bdo><ul id='hycPd'></ul>
              • <small id='hycPd'></small><noframes id='hycPd'>

              • 本文介绍了Javascript:覆盖 XMLHttpRequest.open()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我如何能够覆盖 XMLHttpRequest.open() 方法,然后捕获并更改它的参数?

                How would I be able to override the XMLHttpRequest.open() method and then catch and alter it's arguments?

                我已经尝试过代理方法,但它不起作用,尽管在调用 XMLHttpRequest() 时删除了打开覆盖:

                I've already tried the proxy method but it didn't work, although removing the open over-rid when XMLHttpRequest() was called:

                (function() {
                    var proxied = window.XMLHttpRequest.open;
                    window.XMLHttpRequest.open = function() {
                        $('.log').html(arguments[0]);
                        return proxied.apply(this, arguments);
                    };
                })();
                

                推荐答案

                你不是在修改 XMLHttpRequest objects 继承的 open 方法,只是在 XMLHttpRequest objects 中添加一个方法code>XMLHttpRequest 构造函数 实际上从未使用过.

                You are not modifying the open method inherited by XMLHttpRequest objects but just adding a method to the XMLHttpRequest constructor which is actually never used.

                我在 facebook 中尝试了这段代码,我能够捕捉到请求:

                I tried this code in facebook and I was able to catch the requests:

                (function() {
                    var proxied = window.XMLHttpRequest.prototype.open;
                    window.XMLHttpRequest.prototype.open = function() {
                        console.log( arguments );
                        return proxied.apply(this, [].slice.call(arguments));
                    };
                })();
                
                /*
                    ["POST", "/ajax/chat/buddy_list.php?__a=1", true]
                    ["POST", "/ajax/apps/usage_update.php?__a=1", true]
                    ["POST", "/ajax/chat/buddy_list.php?__a=1", true]
                    ["POST", "/ajax/canvas_ticker.php?__a=1", true]
                    ["POST", "/ajax/canvas_ticker.php?__a=1", true]
                    ["POST", "/ajax/chat/buddy_list.php?__a=1", true]
                */
                

                所以是的,需要将 open 方法添加到 XMLHttpRequest 原型 (window.XMLHttpRequest.prototype) 而不是 XMLHttpRequest 构造函数 (window.XMLHttpRequest)

                So yeah the open method needs to be added to XMLHttpRequest prototype (window.XMLHttpRequest.prototype) not XMLHttpRequest constructor (window.XMLHttpRequest)

                这篇关于Javascript:覆盖 XMLHttpRequest.open()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:跨站 XMLHttpRequest 下一篇:在 chrome 开发工具中隐藏 401 console.error 在 fetch(

                相关文章

                最新文章

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

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

                    <legend id='gzMS0'><style id='gzMS0'><dir id='gzMS0'><q id='gzMS0'></q></dir></style></legend>
                    • <bdo id='gzMS0'></bdo><ul id='gzMS0'></ul>