Skip to content

Instantly share code, notes, and snippets.

@luismartinezs
Last active June 18, 2021 07:57
Show Gist options
  • Save luismartinezs/fefffec1748de0f728a3d6e3aaee841a to your computer and use it in GitHub Desktop.
Save luismartinezs/fefffec1748de0f728a3d6e3aaee841a to your computer and use it in GitHub Desktop.
Async Call template #js
async function asyncCall(url) {
return fetch(url)
.then(response => response.json())
.then(responseJson => {
return responseJson;
})
.catch(error => {
throw error;
});
}
let req, json;
const url =
"https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json";
req = new XMLHttpRequest();
req.open("GET", url, true);
req.onload = () => {
json = JSON.parse(req.responseText);
doSomething(json);
};
req.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment