Because a cross-domain request will send an OPTIONS request first, it is necessary to judge the OPTIONS request and return it directly
if(strtoupper($_SERVER['REQUEST_METHOD'])== 'OPTIONS'){ header("Access-Control-Allow-Origin:*"); header("Access-Control-Allow-Headers:content-type"); header("Access-Control-Request-Method:GET,POST"); exit; }
When returning json data, you need to add it to the header
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET,POST'); header('Access-Control-Allow-Headers: Destination, Content-Type, User-Agent, X-Requested-With, If-Modified-Since'); header('Access-Control-Allow-Credentials: true');