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

133
Vistas
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 Respuestas
Responde la pregunta

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