执行后捕获所有事件后事件

时间:2015-02-16 16:29:32

标签: javascript jquery

我的项目中有超过100个事件请求。 但基本上,所有这些请求都在json中返回相同的格式。

{status: 200, message: "the message", id: 50}

{status: 500, message: "the message", id: 50}

和那些类似的消息,但是当执行完成以显示消息时,有一种方法可以捕获所有的帖子事件吗? 我正在尝试为所有请求构建通用接收器。有可能吗?

1 个答案:

答案 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);
    };
})();