0

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 Answers 2

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Welcome to StackOverflow, I originally voted this down due to formatting but I figure it's probably better to give you some feedback. Check out this guide for how to format your answer so that it might be readable and understandable by someone who may not know exactly what "the Header set Access-Control-Allow-Origin * setting" is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.