小编Har*_*ian的帖子

在Javascript中拦截Fetch()API响应和请求

我想拦截Javascript中的fetch API请求和响应.

例如:在发送请求之前要拦截请求URL并且一旦获得响应就想拦截响应.

以下代码用于拦截所有XMLHTTPRequest的响应.

(function(open) {
 XMLHttpRequest.prototype.open = function(XMLHttpRequest) {
    var self = this;
    this.addEventListener("readystatechange", function() {
        if (this.responseText.length > 0 && this.readyState == 4 && this.responseURL.indexOf('www.google.com') >= 0) {
            Object.defineProperty(self, 'response', {
                get: function() { return bValue; },
                set: function(newValue) { bValue = newValue; },
                enumerable: true,
                configurable: true
            });
            self.response = 'updated value' //Intercepted Value 
        }
    }, false);
    open.apply(this, arguments);
};
})(XMLHttpRequest.prototype.open);
Run Code Online (Sandbox Code Playgroud)

我想为Fetch()API实现相同的功能.

提前致谢..

javascript ajax xmlhttprequest interceptor fetch-api

13
推荐指数
4
解决办法
7489
查看次数

角度2材质水平滚动数据表边框问题

我在我的应用程序中使用Angular Material Data表。我需要显示带有水平滚动表的多列。我面临表格行边框的问题。它没有显示行的整个宽度。请检查所附图片以供参考。请帮助我解决此问题。

请检查链接以获取代码参考

https://stackblitz.com/edit/angular-mdxik6?file=app%2Ftable-basic-example.html

在此处输入图片说明

提前致谢。

angular-material angular-material2 angular5

5
推荐指数
1
解决办法
1万
查看次数