PHP
49
Вклад в тег
Какого его не может получить «fetch»?Через браузер вы обращаетесь от домена эндпоинта, от которого хотите получить информацию.
const proxyUrl = 'https://api.allorigins.win/get?url=';
const targetUrl = 'https://rutube.ru/api/video/37daa4e656174d04db06c5fca7548751';
fetch(proxyUrl + encodeURIComponent(targetUrl))
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
// данные могут быть внутри data.contents
console.log('Data retrieved:', JSON.parse(data.contents));
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});