javascript - Track XMLHTTPRequest results -


i have system built of many modules use ajax posts , gets. if monitor results of these requests, can know if system responsive - ie if browser still connected ip source.

i can hand inject callback methods in jquery's ajax .fail(). have done can easy forget , adds lot of code, system requires ajax.

i saw interesting code intercept xmlhttprequest open prototype method

(function(open) {     xmlhttprequest.prototype.open = function() {         this.addeventlistener("readystatechange", function() {             console.log(this.readystate);         }, false);         open.apply(this, arguments);     }; })(xmlhttprequest.prototype.open); 

i looked through api, https://developer.mozilla.org/en-us/docs/web/api/xmlhttprequest, did not find somewhere intercept success/failed/timed out requests. possible?

it's listening appropriate events, appear in left sidebar in link under "events".

that said, consider using / taking inspiration of zone.js.

a zone execution context persists across async tasks. can think of thread-local storage javascript vms.


Comments