Donny Gunawan
Donny Gunawan

Reputation: 363

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

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.

Upvotes: 0

Views: 1356

Answers (2)

Parav01d
Parav01d

Reputation: 318

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

Upvotes: 0

Korvin Szanto
Korvin Szanto

Reputation: 4501

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;

Upvotes: 1

Related Questions