A
A
Alex_872021-05-16 15:50:19
JavaScript
Alex_87, 2021-05-16 15:50:19

How to fix request blocking error?

Hello! Please help me with the following error when fetching a product from mongoDB:

Request from foreign origin blocked: (Reason: CORS header "Access-Control-Allow-Origin" is missing).

From a search on the net, I understand that you need to give access to read this request. This is done with the following line: The
Access-Control-Allow-Origin: *

question is where to register it, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aza Broflovski, 2021-05-18
@AzaBroflovski

Hello! Please help me solve the problem with the following error that occurs when displaying a product from mongoDB:

This doesn't happen when the product is removed from the MongoDB. This is a browser limitation , you can send a request using programs such as Postman , etc. to verify this. By sending a request, you will successfully receive your response from the server.
To solve your problem, your web server should return an appropriate header that tells the browser that the client is allowed to receive data from your server.
This header looks like this:
Access-Control-Allow-Origin: https://site.com
Such a header will mean that it site.comcan only knock on your server.
In order to allow everyone to knock on your server, you can set *this symbol as a value.
Access-Control-Allow-Origin: *
You can read more about CORS here ..
And what should I do then?

p.s вот вам совет, как гуглить ваше решение:
$webserver_name cors header или $framework_name cors header

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question