As I take control of all AJAX responses on a global scale, I find myself searching for an elegant solution to identify the method (such as POST/PUT/GET
) that was initially used to make the request triggering the intercepted response.
Below is my approach for intercepting these requests:
(function() {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener('load', function() {
if (this.readyState === 4) {
// How can I determine the original request method?
}
});
origOpen.apply(this, arguments);
};
})();