C
C
cocomuffin2019-08-14 11:10:20
JavaScript
cocomuffin, 2019-08-14 11:10:20

When sending a request, a CORS error occurs, but the data is received, how to avoid the error and collect the received data?

Good day!
The situation is this: I'm trying to pull an array of product objects from the eda.ru website through a search, I send a request, but I get a CORS error, while the data itself comes! That is, I just send a request a la

fetch('https://eda.ru/Ingredient/FindByName?term=молоко').then(res => res.json()).then(console.log).catch(console.warn);

and I get an error, but at the same time I can see that the data from the food came. How can I get around this error and get the data for processing? Of course, there is no access to eda.ru, they also do not have an API. The idea is to then get the recipe in the form of html for the products, and parse it already at home.
5d53c16887419121707918.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2019-08-14
@inoise

People who don't want to google it's not funny anymore. The browser will not process a response from a server from a different domain name unless allowed by the resource. Dot. This is CORS and you can do 2 things with this: write a handler on the backend or make an http proxy to your domain and receive data from there

R
RokeAlvo, 2019-08-14
@RokeAlvo

Nothing from the browser. Parse the food page on the server, give the application ready-made data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question