Skip to content

Instantly share code, notes, and snippets.

@moisescastillo
Created August 16, 2020 00: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 moisescastillo/b7ba1d1c244a4e4438159b53811c61e4 to your computer and use it in GitHub Desktop.
Save moisescastillo/b7ba1d1c244a4e4438159b53811c61e4 to your computer and use it in GitHub Desktop.
Javascript fetch example 02
fetch("https://jsonplaceholder.typicode.com/posts/")
.then(function(response) {
if (response.ok) {
response.json().then(function(dataJson) {
dataJson.forEach((value, index) => {
console.log(value.id);
console.log(value.title);
console.log(value.body);
console.log(value.userId);
});
});
} else {
console.log('Error en la respuesta HTTP');
return;
}
}).catch(error => {
console.log(`Error en la peticion ${error}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment