0
votes

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.

2

2 Answers

1
votes

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;
0
votes

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