Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda