Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Global Callbacks for XMLHTTPRequests (progress, load, error, ...)

License

Notifications You must be signed in to change notification settings

AirConsole/xmlhttprequest-global-callbacks

Repository files navigation

XMLHttpRequest Global Callbacks

A javascript library that allows for global XMLHTTPRequest callbacks

Why do you need this library?

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.

How to use this library

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.

Arguments passed to global callbacks

  • event: The original event that was triggered
  • request_method: The request method passed to XMLHTTPRequest.open()
  • request_url: The url passed to XMLHTTPRequest.open()

About

Global Callbacks for XMLHTTPRequests (progress, load, error, ...)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published