The server suddenly stopped responding to cross-domain requests (maybe a software update on the hosting)

client (js):

Request.onload = answer; Request.open("post", "https://xxx.php", false); Request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8"); Request.send(forSend); 

server (php):

 header('Content-Type: application/json'); header('X-Content-Type-Options nosniff'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST'); header('Access-Control-Allow-Headers: Content-Type'); header('Access-Control-Allow-Credentials: true'); 

as a result in the console:

 Failed to load https://xxx.php: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://xxx.php'. 

Tell me how to resolve requests or what else could be the problem?

  • Look in the network tab, which headers come from the server to Request.send(forSend); . Maybe there is not only Access-Control-Allow-Origin , but all the rest. - Visman
  • Thanks, I found the error after reviewing the answer, the syntax error was on the server, I made it through inattention) - Samsonin

1 answer 1

Leave only the header('Access-Control-Allow-Origin: *');