我的项目中有超过100个事件请求。 但基本上,所有这些请求都在json中返回相同的格式。
{status: 200, message: "the message", id: 50}
或
{status: 500, message: "the message", id: 50}
和那些类似的消息,但是当执行完成以显示消息时,有一种方法可以捕获所有的帖子事件吗? 我正在尝试为所有请求构建通用接收器。有可能吗?
答案 0 :(得分:0)
(function () {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (a, b) {
//console.log(this);
var x = a;
var y = b;
this.addEventListener('load', function () {
//console.log(this);
var z = JSON.parse(this.response);
//Here you can filter all the request results
});
origOpen.apply(this, arguments);
};
})();