function translate(){
fetch('https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&hl=ru&dt=t&dt=bd&dj=1&source=icon&tk=467103.467103&q=привет', {
method: 'get',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
mode : 'no-cors'
//body: JSON.stringify({a: 7, str: 'Some string: &=&'})
}).then(res=>res.json())
.then(res => console.log(res));
}
console.log(translate())
VM142:10 Uncaught (in promise) SyntaxError: Unexpected end of input
at <anonymous>:10:18
Access to fetch at 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&hl=ru&dt=t&dt=bd&dj=1&source=icon&tk=467103.467103&q=%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' from origin 'https://stackoverflow.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
VM52:2 GET https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&hl=ru&dt=t&dt=bd&dj=1&source=icon&tk=467103.467103&q=%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82 net::ERR_FAILED
translate @ VM52:2
(anonymous) @ VM52:12
fetch-post-json-data:1 Uncaught (in promise) TypeError: Failed to fetch
<div class="sidebar__inner"><div class="sidebar__content"><div class="sidebar__section"><h4 class="sidebar__section-title">Смежные разделы</h4><nav class="sidebar__navigation"><ul class="sidebar__navigation-links"><li class="sidebar__navigation-link"><a class="sidebar__link" href="/document">Документ</a></li><li class="sidebar__navigation-link"><a class="sidebar__link" href="/events">Введение в события</a></li><li class="sidebar__navigation-link"><a class="sidebar__link" href="/event-details">Интерфейсные события</a></li><li class="sidebar__navigation-link"><a class="sidebar__link" href="/forms-controls">Формы, элементы управления</a></li><li class="sidebar__navigation-link"><a class="sidebar__link" href="/loading">Загрузка документа и ресурсов</a></li><li class="sidebar__navigation-link"><a class="sidebar__link" href="/ui-misc">Разное</a></li></ul></nav></div><div class="sidebar__section"><div class="sidebar__section-title">Поделиться</div><a class="share share_tw sidebar__share" href="https://twitter.com/share?url=https%3A%2F%2Flearn.javascript.ru%2Fdocument" rel="nofollow"></a><a class="share share_fb sidebar__share" href="https://www.facebook.com/sharer/sharer.php?s=100&p[url]=https%3A%2F%2Flearn.javascript.ru%2Fdocument" rel="nofollow"></a><a class="share share_vk sidebar__share" href="https://vkontakte.ru/share.php?url=https%3A%2F%2Flearn.javascript.ru%2Fdocument" rel="nofollow"></a></div><div class="sidebar__section"><a class="sidebar__link" href="https://github.com/javascript-tutorial/ru.javascript.info/blob/master/2-ui/1-document" rel="nofollow">Редактировать на GitHub</a></div></div></div>
let a = document.getElementsByClassName('sidebar__inner')[0].innerText;
console.log(a)
let array =["Related Sections",
"Document",
"Introduction to Events",
"Interface events",
"Forms, controls",
"Download document and resources",
"Miscellanea",
"Share",
"Edit on GitHub"]
Array.from( document.getElementsByClassName('sidebar__inner') )
.forEach((element, index) => element.innerText = array[index]);
Смежные разделы
Документ
Введение в события
Интерфейсные события
Формы, элементы управления
Загрузка документа и ресурсов
Разное
Поделиться
Редактировать на GitHub