A javascript library that allows for global XMLHTTPRequest callbacks
Assume you would like to globally log onerror events in XMLHTTPRequests. It's easier to have one global callback that does this, then setting onerror on every request.
Just download xmlhttprequest-global-callbacks.min.js and include it in your html page.
<script type="text/javascript" src="xmlhttprequest-length-computable.min.js"></script>
Now you can register global callbacks for all XMLHTTPRequests using window.xmlHTTPRequestGlobalCallbacks
window.xmlHTTPRequestGlobalCallbacks = {
"progress": function(event, request_method, request_url) {
console.log(event, request_method, request_url);
},
"load": function(event, request_method, request_url) {
console.log(event, request_method, request_url);
},
"error": function(event, request_method, request_url) {
console.log(event, request_method, request_url);
}
}
Any event name is possible.
event
: The original event that was triggeredrequest_method
: The request method passed toXMLHTTPRequest.open()
request_url
: The url passed toXMLHTTPRequest.open()