我想拦截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实现相同的功能.
提前致谢..
我在我的应用程序中使用Angular Material Data表。我需要显示带有水平滚动表的多列。我面临表格行边框的问题。它没有显示行的整个宽度。请检查所附图片以供参考。请帮助我解决此问题。
请检查链接以获取代码参考
https://stackblitz.com/edit/angular-mdxik6?file=app%2Ftable-basic-example.html
提前致谢。