Last active
June 18, 2021 07:57
-
-
Save luismartinezs/fefffec1748de0f728a3d6e3aaee841a to your computer and use it in GitHub Desktop.
Async Call template #js
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
async function asyncCall(url) { | |
return fetch(url) | |
.then(response => response.json()) | |
.then(responseJson => { | |
return responseJson; | |
}) | |
.catch(error => { | |
throw error; | |
}); | |
} |
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
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