Created
December 11, 2013 01:17
-
-
Save Rich-Harris/7903510 to your computer and use it in GitHub Desktop.
quick and dirty XHR helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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