php 解决跨域问题

后台返回数据时加入这三句就可以了

   header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        header('Access-Control-Request-Method: *'); 
 
 
tp5: 
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Max-Age: 1728000');
if (strtoupper(request()->method()) == "OPTIONS") {
return Response::create()->send();
}
原文地址:https://www.cnblogs.com/kerryw/p/8939214.html