Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Error de CORS con JS async/await pero no cuando pego la URL directamente en el navegador

Cuando coloco la URL http://192.168.1.136:8080/epost_backend/api.php?method=getCategories en Chrome, devuelve el resultado de la API que he creado.

Imagen de salida Pero cuando pongo exactamente la misma URL en una función javascript async/await, siempre queda atrapada en el error de captura...

Resultado de la función async/await

Aquí está la pestaña de red que muestra el error CORS: ERRORES DE LAS HERRAMIENTAS DE DESARROLLO

Aquí está el archivo HTML/JS:

 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <script> async function getCategories(){ try{ const res = await fetch("http://192.168.1.136:8080/epost_backend/api.php?method=getCategories") const output = await res.json() document.getElementById('result').innerHTML = output } catch{ document.getElementById('result').innerHTML = "THERE WAS AN ERROR" } } </script> <body onLoad='getCategories()'> <h1>RESULT</h1> <div id='result'></div> </body> </html>

¿Alguna idea sobre lo que estoy haciendo mal o por qué no puedo obtener esta información de esta manera?

Estaré monitoreando y respondiendo cualquier duda....

¡Muchas gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente necesita habilitar CORS en su servidor PHP. Para ello, establezca una serie de encabezados. Como mínimo, establezca Access-Control-Allow-Origin "*" para permitir que todos los orígenes realicen solicitudes a su servidor PHP.

Se puede encontrar una buena referencia en este sitio: https://enable-cors.org/server_php.html

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!