• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

125
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?

almost 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda