讨论数量:
你这是因为跨域引起的,因为前端和后端使用了不同的域名。可以通过在 Laravel 中引用跨域处理的中间件,或者在 nginx 中设置跨域处理信息即可。
Laravel 处理方案
在 app/Http/Kernel.php
的中间件配置中,配置 HandleCors
中间件即可,如下:
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
];
Nginx 处理方案
在 nginx 配置文件中,增加以下跨域处理配置即可:
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
return 204;
}
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET,POST,DELETE,PUT,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
你这是因为跨域引起的,因为前端和后端使用了不同的域名。可以通过在 Laravel 中引用跨域处理的中间件,或者在 nginx 中设置跨域处理信息即可。
Laravel 处理方案
在
app/Http/Kernel.php
的中间件配置中,配置HandleCors
中间件即可,如下:Nginx 处理方案
在 nginx 配置文件中,增加以下跨域处理配置即可: