Created
October 2, 2018 18:13
-
-
Save esironal/740bf0e9f43e70663b81e6cd26729a63 to your computer and use it in GitHub Desktop.
fetch-example.js
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 content = document.getElementById('content'); | |
fetch('//api.github.com/users/esironal') | |
.then(function (res) { | |
if (res.status >= 400) { | |
throw new Error("Bad response from server"); | |
} | |
return res.json(); | |
}) | |
.then(function (user) { | |
content.innerHTML = JSON.stringify(user, null, ' '); | |
}) | |
.catch(function (err) { | |
content.innerHTML = err.message; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment