G
G
guerrrka2018-10-05 20:40:36
Laravel
guerrrka, 2018-10-05 20:40:36

Access-Control-Allow-Origin error when requesting laravel server. What to do?

I am writing a client (login/registration) using VUE. When registering, I make a request to my own Laravel API. The following error pops up in the browser console

Failed to load test.ru/api/user/register: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' localhost:8080 ' is therefore not allowed access.

What to do? (tried ajax - same error)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Filippenko, 2018-10-05
@guerrrka

The essence of the problem is that POST requests from third-party domains are cut off for security reasons.
Solution, allow such requests. https://github.com/barryvdh/laravel-cors here is a package that might help

J
JhaoDa, 2018-10-05
@JhaoDa

Learn what CORS is and how to live with it.
PS And learn to google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question