G
G
gevrog2021-09-16 13:23:03
CORS
gevrog, 2021-09-16 13:23:03

Error: Access to fetch at 'localhost/userProject/userRegistration.php' from origin 'localhost:19006' has been blocked by CORS policy?

I studied the issue, installed the Express and cors libraries but did not help
61431ad309908444317658.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-09-16
@Rsa97

localhost and localhost:19006 are different sites from the browser's point of view.
CORS headers must be returned, including for OPTIONS requests.

header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Vary: Origin');

And if you use cookies, then you also need to set withCredentials=truefor AJAX requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question