loadProducts(data) {
const stock = document.querySelector(".stock__section");
data.product.forEach(item => {
const productId = item.id;
const productName = item.name;
const productTitle = item.title;
const productImage1 = item.image1;
const productImage2 = item.image2;
const productAlt = item.alt;
const productUrl = item.url;
const productOldPrice = item.oldprice;
const productPrice = item.price;
let productsStart = <div class="product__box__wrap">;
let productsEnd = "</div>";
let productsContent = `
<div class="product__box__wrap" id="${productId}">
<div class="product__box">
<button class="product__box__favourite__button"><img src="img/favourite.svg" alt="" class="product__box__favourite__img"></button>
<a href="" class="product__box__img__link">
<div class="product__box__img__wrap" title="${productTitle}">
<img src="img/${productImage1}" alt="${productAlt}" class="product__box__img" title="${productTitle}">
</div>
<div class="product__box__img__wrap">
<img src="img/${productImage2}" alt="${productAlt}" class="product__box__img" title="${productTitle}">
</div>
</a>
<a href="${productUrl}" title="${productTitle}" class="product__box__title">${productName}</a>
<div class="product__box__prices">
<div class="product__box__old__price"><span class="product__box__old__price__number">${productOldPrice}</span><span class="product__box__old__price__currency">₴</span></div>
<div class="product__box__price"><span class="product__box__price__number">${productPrice}</span><span class="product__box__price__currency">₴</span></div>
</div>
</div>
</div>
`;
let products = "";
products += productsStart;
products += productsContent;
products += productsEnd;
stock.insertAdjacentHTML("beforeend", products);
});
}
function loadProductsData(data) {
fetch("json/products.json")
.then((response) => response.json())
.then((data) => {
alert("ucegefefffe")
loadProducts(data);
})
.catch((error) => {
console.error("Error fetching products data:", error);
});
}
loadProductsData();
``` let productsStart = <div class="product__box__wrap">; let productsEnd = "</div>"; ``` Чтобы таким не страдать, есть document.createElement Но по сабжу, ошибка может быть где угодно. Ставьте точку останову в начале функции и дебажьте пока не найдете
Обсуждают сегодня