Categoría: JavaScript
De enunpimpam
| Línea 20: | Línea 20: | ||
const datos = await respuesta.json() | const datos = await respuesta.json() | ||
console.log(datos) | console.log(datos) | ||
| + | })() | ||
| + | </syntaxhighlight> | ||
| + | Petición de una lista de 50 peliculas de Sci-ficción | ||
| + | <syntaxhighlight lang="js"> | ||
| + | (async function load(){ | ||
| + | // await | ||
| + | //action, sci-fi, animation, fantasy | ||
| + | async function getDatos(url) { | ||
| + | const respuesta = await fetch(url) | ||
| + | const datos = await respuesta.json() | ||
| + | return datos | ||
| + | } | ||
| + | const scifiList = await getDatos("https://yts.mx/api/v2/list_movies.json?genre=sci-fi&limit=50") | ||
| + | console.log('scifiList', scifiList) | ||
})() | })() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revisión del 12:31 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)
})()
Petición de una lista de 50 peliculas de Sci-ficción
(async function load(){
// await
//action, sci-fi, animation, fantasy
async function getDatos(url) {
const respuesta = await fetch(url)
const datos = await respuesta.json()
return datos
}
const scifiList = await getDatos("https://yts.mx/api/v2/list_movies.json?genre=sci-fi&limit=50")
console.log('scifiList', scifiList)
})()
Páginas en la categoría «JavaScript»
Las siguientes 9 páginas pertenecen a esta categoría, de un total de 9.