Last active
August 7, 2016 09:43
-
-
Save aneelkkhatri/2e197eaddeb2285cbf958374354ba2d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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