Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

57
Vistas
Why does fetch with only 1 then not work here?
function postFetch(data) {
  document.getElementById('test').innerHTML = data.name;
}

//fetch("test").then(data=>data.json()).then(res=>{postFetch(res)});
fetch("test").then(data => postFetch(data.json()))

test is a json file with {"name":"Carla"} in it. And i have a html page with a element with id test in it, that sources this script. As it is, the page displays undefined. However, if i switch the uncomment the commented line and comment the next, it displays the intended Carla on the page. Why don't they behave the same?

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos