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:
- ThinkPHP interface cross domain request error [Solved]
- [PHP] Solve Call-time pass-by-reference has been removed
- Error: call-time pass-by-reference has been removed
- How to Solve phpExcel Error: ERR_INVALID_RESPONSE
- [PHP] Solve the problem that the new version of Chrome’s same-site policy cannot record cookies across domains
- Error during PHP installation and configuration error: off_t undefined; check your library configuration
- Laravel5.5 Error: SQLSTATE[42000] Syntax error or access violation 1071 Specified key was too long; max k
- composer Failed to decode response: zlib_decode(): data error
- [Solved] Request exceeded the limit of 10 internal redirects due to possible configuration error
- [Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- [Solved] Artisan error: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
- How to Solve PHP Fatal error: Namespace declaration statement has to be the very first statement
- PHP large file upload error 413: request entity too large [How to Solve]
- php Error: mail() Failed to connect to mailserver at “localhost” port 25
- [PHP] Solve the limitation of uploading files in nginx php 413 Request Entity Too Large
- [Solved] yii error: Setting unknown property: yii\console\Request: :cookieValidationKey
- Workman Run Error: stream_socket_server() has been disabled for security reasons
- How to Solve PHP Error: no package’oniguruma’ found
- [Solved] laravel proc_get_status() has been disabled for security reasons