const couponsFrame=document.getElementById("coupons-frame"); const newsFrame=document.getElementById("news-frame"); window.addEventListener('load',async function(){ try{ const response1=await fetch(`/api/coupons/getAllCoupons`); const response2=await fetch(`/api/news/getAllEvents`); if(response1.ok){ const coupons=await response1.json(); coupons.forEach(coupon=>{ const couponDiv=document.createElement("div"); couponDiv.classList.add("new-item"); couponDiv.innerHTML=`
${coupon.code}
${coupon.description}
`; couponsFrame.appendChild(couponDiv); }) } else{ console.log("error with coupons") } if(response2.ok){ const news=await response2.json(); news.forEach(event=>{ const eventDiv=document.createElement("div"); eventDiv.classList.add("new-item"); eventDiv.innerHTML=`${event.text}
${event.imgSrc ? `` : ''}`; newsFrame.appendChild(eventDiv); }) } else{ console.log("error with news") } } catch(error){ console.error("Error fetching data:", error); } });