Skip to content

Instantly share code, notes, and snippets.

@moisescastillo
Created August 16, 2020 00:36
Show Gist options
  • Save moisescastillo/abc99f39c61fa36c1c1ca71e31dc0456 to your computer and use it in GitHub Desktop.
Save moisescastillo/abc99f39c61fa36c1c1ca71e31dc0456 to your computer and use it in GitHub Desktop.
Javascript fetch example 03
fetch("https://jsonplaceholder.typicode.com/posts/")
.then(function(response) {
if (response.status !== 200) {
console.log('Error en la respuesta HTTP');
return;
}
return 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);
});
}).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