Skip to content

Instantly share code, notes, and snippets.

@anabastos
Last active April 17, 2018 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anabastos/ff87fd9ee8c46b09ad8125a0eb5f02d4 to your computer and use it in GitHub Desktop.
Save anabastos/ff87fd9ee8c46b09ad8125a0eb5f02d4 to your computer and use it in GitHub Desktop.
*~my Fetch~*
const fetch = (url, verb, onSuccess, onFail) => {
const asyncqued = !!onSuccess;
asyncqued && req.onreadystatechange = processReqChange;
const req = (window.XMLHttpRequest && new XMLHttpRequest())
|| (window.ActiveXObject && new ActiveXObject("Microsoft.XMLHTTP"));
callback(req, onSuccess, onFail);
req.open(verb, url, asyncqued);
req.send(null);
return asyncqued ? req : req.responseText;
}
const callback = (req, onSuccess, onFail) => {
if (req.readyState == 4) {
if (req.status == 200) {
onSuccess && onSuccess(req.responseText, url, req);
} else {
onFail && onFail(url, req);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment