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

110
Views
Falta la solicitud POST entre dominios con CORS devuelve access-control-allow-origin

Quiero realizar una solicitud de dominio cruzado de localhost a localhost: 81, pero constantemente falta CORS-Header'Access-Control-Allow-Origin'. Pero configuré el encabezado en postHere.php. También probé header('Access-Control-Allow-Origin: *'); y tampoco funciona?

postHere.php

 <?php switch ($_SERVER['HTTP_ORIGIN']) { case 'http://localhost': case 'https://localhost': header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); header('Access-Control-Max-Age: 1000'); header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With'); break; }

Archivo HTML en localhost desde el que quiero enviar a localhost:81

 <html> <head> <script src="//code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <script> $.ajax({ type: 'POST', url: 'http://localhost:81/postHere.php', crossDomain: true, data: '{"some":"json"}', dataType: 'json', success: function(responseData, textStatus, jqXHR) { var value = responseData.someKey; }, error: function (responseData, textStatus, errorThrown) { alert('POST failed.'); } }); </script> </body> </html>

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

0

Debe habilitar su servidor en el segundo origen (en su caso, localhost:81 , aunque probablemente debería usar 8081 en su lugar) para permitir solicitudes de origen cruzado. Consulte las guías de Mozilla sobre eso.

Enlaces: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS https://developer.mozilla.org/en-US/docs/Glossary/CORS

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!