Created
November 6, 2016 23:57
-
-
Save raphaelpor/16f941db21cd6c12c91db3feed3c4c63 to your computer and use it in GitHub Desktop.
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
fetch('file.json') // URL de destino. | |
.then(response => { // 'response' possui todas informações da resposta. | |
if(response.ok) { // Bool para checar a respota. | |
return response.json(); // É necessário transformar o 'body' para json, para que possa ser manipulado | |
} | |
}) | |
.then(data => { // Recebe o 'data' em formato json. | |
console.log(data); | |
}) | |
.catch(err => { // Recebe um objeto contendo as informações do erro. | |
console.log(err.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment