Skip to content

Instantly share code, notes, and snippets.

@aneelkkhatri
Last active August 7, 2016 09:43
Show Gist options
  • Save aneelkkhatri/2e197eaddeb2285cbf958374354ba2d1 to your computer and use it in GitHub Desktop.
Save aneelkkhatri/2e197eaddeb2285cbf958374354ba2d1 to your computer and use it in GitHub Desktop.
var XHRHelper = (function(){
function initParams(params) {
if (!params.type) {
params.type = "GET";
};
}
return {
request: function(params, async = true) {
var xhr = new XMLHttpRequest();
initParams(params);
xhr.onload = function() {
if (params.success) {
params.success(xhr);
};
};
xhr.onerror = function () {
if (params.error) {
params.error(xhr);
};
}
xhr.open(params.type, params.url, async);
xhr.send();
return xhr;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment