delegate open and send for XMLHttpRequest by rewrite the prototype

 

 var sendProxied = window.XMLHttpRequest.prototype.send;
    window.XMLHttpRequest.prototype.send = function() {var object = {};
        let data = arguments[0]
        if (data && data.forEach) {
            data.forEach((value, key) => object[key] = value);
            var json = JSON.stringify(object);
        }
        return sendProxied.apply(this, [].slice.call(arguments));
    }

 

    var openProxied = window.XMLHttpRequest.prototype.open;
    window.XMLHttpRequest.prototype.open = function() {
        return openProxied.apply(this, [].slice.call(arguments));
    }

 

posted @ 2023-08-03 21:28  zyip  阅读(10)  评论(0编辑  收藏  举报