• php代码
#检测是否预检
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
    header('Access-Control-Max-Age:86400'); #设置预检缓存时间 秒
    header('Access-Control-Allow-Methods:OPTIONS,HEAD,GET,POST,PUT'); #请求方法限制
    header('Access-Control-Allow-Origin:*');
    #header('Access-Control-Allow-Credentials:true'); #如此项为true,Access-Control-Allow-Origin必须为域名
    #header('Access-Control-Allow-Headers:Content-Type, Content-Length, Authorization, Accept, X-Requested-With');#请求头限制 可以不设
    die('{"status":true,"msg":"请求成功","data":[]}');
}