From a7cb70c2117b8a114c0cca87377a25dc431e5640 Mon Sep 17 00:00:00 2001 From: Valeria Fadeeva Date: Sun, 10 Dec 2023 01:37:11 +0500 Subject: [PATCH] Update --- public/assets/js/script.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/assets/js/script.js b/public/assets/js/script.js index dd8a608..66c5224 100644 --- a/public/assets/js/script.js +++ b/public/assets/js/script.js @@ -78,10 +78,11 @@ async function bodyFetch(url) { let response = await fetch(tplUrl); let body = document.getElementById('body'); + if(tplUrl == 'news.tpl.html') {let res = await fetchData();} + if (response.ok) { // если HTTP-статус в диапазоне 200-299 // получаем тело ответа (см. про этот метод ниже) let text = await response.text(); - if (tplUrl == 'news.tpl.html') {await fetchData();} body.innerHTML = text; } else { body.innerHTML = "Ой всё сломалось :("; @@ -139,10 +140,12 @@ let fetchPage = async function(evt) { const linkText = this.text.trim(); const title = document.title + ": " + linkText; + if (tplUrl == 'news.tpl.html') {let res = await fetchData();} + try { const response = await fetch(tplUrl, { signal }); text = await response.text(); - if (tplUrl == 'news.tpl.html') {await fetchData();} + } catch (error) { // DOMException: The user aborted a request. console.log('Error: ', error)