Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
Why is JSON data sent from server to browser undefined?

I want to make a request to my server with fetch(), and have data returned to be used in the front end app.

here is my route:

    app.get('/game-data', (req, res) => {
    res.json({ data: "test-data" })
})

and here is my request:

button.addEventListener('click', () => {
    fetch('/game-data', {
        headers: {
            'accept': 'application / json',
            'Content-Type': 'application/json'
        }
    })
        .then(response => {
            console.log(response)
            response.json()
        })
        .then(myJson => {
            console.log(myJson)
        })
})

I can see the response object in the first console log, but response.json(), or response.text() are returning undefined.

Please help me see what I am missing!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to return the value to use it in another .then

.then(response => {
        console.log(response)
        return response.json()
    })
about 4 years ago · Juan Pablo Isaza Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda