[Solved] has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check: No

Has been blocked by CORS policy: response to preflight request doesn’t pass access control check: no ‘access control allow origin’ header is present on the requested resource.
seeing this error in the webpage, I know that it must be a cross domain problem of Ajax requests.
there are two solutions to this problem, as you should know after reading my article, Before I sent the front-end solution, I don’t know how to flip through my article list
today we talk about the server-side solution
add this code before the JSON data to be returned:


// Specify to allow access to other domains
header('Access-Control-Allow-Origin:*');
// Response type
header('Access-Control-Allow-Methods:POST');
// response header settings
header('Access-Control-Allow-Headers:x-requested-with,content-type');

Here is the PHP code, you can also change it to the corresponding java code.


Read More: