如何截获XMLHttpResponses的?
我可以使用以下内容拦截发送。我尝试覆盖proto.response
,但从未成功。
(function(xhr) {
var
proto = xhr.prototype,
_send = proto.send,
_open = proto.open;
// overload open() to access url and request method
proto.open = function() {
// store type and url to use in other methods
this._method = arguments[0];
this._url = arguments[1];
_open.apply(this, arguments);
}
// overload send to intercept data and modify
proto.send = function() {
// using properties stored in open()
if (this._method.toLowerCase() === 'post') {
// modify data to send
}
_send.apply(this, arguments);
}
})(XMLHttpRequest);