找到你要的答案

Q:How can i do CORS POST request on Laravel 5 and AngularJS?

Q:我怎么能在5和AngularJS做laravel CORS请求?

i am use

github.com/barryvdh/laravel-cors

with default configuration

and i was success with GET request,

when i do POST request,

on console network tab, that POST status is 200,

BUT i got an error

XMLHttpRequest cannot load http://localhost:8000/api/data. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

我使用

github.com/barryvdh/laravel-cors

使用默认配置

我得到了成功的要求,

当我做POST请求,

在控制台网络选项卡上,该岗位状态为200,

但我有一个错误

XMLHttpRequest cannot load http://localhost:8000/api/data. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

answer1: 回答1:

You'll have to define the Access-Control-Allow-Origin header on your laravel application.

To allow ANY domain to request resources from your laravel application:

$response = Response::make($contents, $statusCode);
$response->header('Access-Control-Allow-Origin', '*');
return $response;

你必须定义访问控制允许原产头你laravel应用。

To allow ANY domain to request resources from your laravel application:

$response = Response::make($contents, $statusCode);
$response->header('Access-Control-Allow-Origin', '*');
return $response;
answer2: 回答2:

You can just put the: Header set Access-Control-Allow-Origin "*"
setting in the Apache configuration or htaccess file.
Then check if your changes are correct: apachectl -t
and restart your webserver sudo service apache2 reload

You can just put the: Header set Access-Control-Allow-Origin "*"
setting in the Apache configuration or htaccess file.
Then check if your changes are correct: apachectl -t
and restart your webserver sudo service apache2 reload

php  angularjs  laravel  laravel-5