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

130
Visualizações
Errors when using the fetch function (JavaScript)

I'm working with AWS API Gateway and I'm getting the following error:

Uncaught TypeError TypeError: Failed to fetch

My API is just returning a simple JSON string. I can get a successful response with curl, Postman and testing via the AWS console. But, using JavaScript, I get an error. I suspect that AWS requires a specific header

I separated the code from the original website. Some unnecessary parts have been removed.

<script type = "text/javascript">
const GET_url = '<url>'
const POST_url = '<url>'

async function getInvokeFromAPI() {
  const response = await fetch(GET_url, {
    method: 'GET'
  });
  const data = await response.json();
}

async function postInvokeFromAPI() {
  const respone = await fetch(POST_url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    }
  });
  const data = await response.json();
}
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It would be helpful to see the console output when the error happens.

But if it works with Postman and not with the fetch API, you are probably having a CORS error.

You can check this page of the MDN for more informations about CORS in case it is your error: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

If it is your error, it will be logged in the browser console in the dev tools.

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