Categoría: JavaScript
De enunpimpam
| Línea 13: | Línea 13: | ||
}) | }) | ||
})</syntaxhighlight> | })</syntaxhighlight> | ||
| + | ==Funciones asincronas== | ||
| + | <syntaxhighlight lang="js"> | ||
| + | (async function load(){ | ||
| + | // await | ||
| + | const respuesta = await fetch("https://yts.mx/api/v2/list_movies.json?genre=action") | ||
| + | const datos = await respuesta.json() | ||
| + | console.log(datos) | ||
| + | })() | ||
| + | </syntaxhighlight> | ||
Revisión del 11:57 31 jul 2020
Traer datos con fetch
fetch("https://randomuser.me/api/")
.then(function(response) {
// console.log(response)
return response.json()
})
.then(function (Usuario){
console.log('Todo los datos en Array', Usuario)
console.log('Solo el Nombre:', Usuario.results[0].name.first)
})
.catch(function(response) {
})
})
Funciones asincronas
(async function load(){
// await
const respuesta = await fetch("https://yts.mx/api/v2/list_movies.json?genre=action")
const datos = await respuesta.json()
console.log(datos)
})()
Páginas en la categoría «JavaScript»
Las siguientes 9 páginas pertenecen a esta categoría, de un total de 9.