on-xmlhttprequest
v1.0.1
Published
Monkey patch for `window.XMLHttpRequest` events
Downloads
5
Readme
on-xmlhttprequest
Monkey patch for window.XMLHttpRequest
events
Install
npm i on-xmlhttprequest
Usage
request
is an instance ofEventEmitter
withmethod
andurl
properties added to itresponse
is also the originalXMLHttpRequest
for your convenience
var onXhr = require('on-xmlhttprequest');
onXhr(function (request) {
request.on('open', function (response) {
console.log('open', request.method, request.url);
});
request.on('done', function (response) {
console.log('done', request.method, request.url, response.status, response.responseText);
});
request.on('abort', function (response) {
console.log('abort', request.method, request.url);
});
request.on('timeout', function (response) {
console.log('timeout', request.method, request.url);
});
request.on('error', function (response) {
console.log('error', request.method, request.url);
});
});