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

363
Visualizações
Fetch request error while I can see the good result in the browser dev tool

I need to fetch JSON data from a localhost server using JS.

The fetch request throws an error:

Uncaught (in promise) SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

It looks like the answer is empty, but when I open the browser dev tool I can see the JSON data in the network section.

fetch(url, init)
 .then(res => res.json()) //return the error

fetch(url, init)
 .then(res => res.text()) //return an empty string

The result I can see in the network section is well formatted and when I copy/paste it to manually use JSON.parse() I get the right result.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have to return the promise and than wait:

const method = async() =>{
    return fetch(url, init)
     .then(res => res.json())
     .catch(err)=>{
       //manage error here
    }
}

than you do :

method().then(res=>....)

For more info look here : How to get data returned from fetch() promise?

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