Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Created December 11, 2013 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rich-Harris/7903510 to your computer and use it in GitHub Desktop.
Save Rich-Harris/7903510 to your computer and use it in GitHub Desktop.
quick and dirty XHR helper
(function ( global ) {
'use strict';
var get;
get = function ( url, callback ) {
var xhr = new XMLHttpRequest();
xhr.open( 'GET', url );
xhr.onload = function () {
callback( xhr.responseText );
};
xhr.send();
};
// export as CommonJS module...
if ( typeof module !== 'undefined' && module.exports ) {
module.exports = get;
}
// ... or as AMD module...
else if ( typeof define !== 'undefined' && define.amd ) {
define( function () { return get; });
}
// ... or as browser global
else {
global.get = get;
}
}( typeof window !== undefined ? window : this ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment