Last change
on this file since 43c9090 was 43c9090, checked in by macagaso <gasoskamarija@…>, 5 weeks ago |
Updated version
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[43c9090] | 1 | const couponsFrame=document.getElementById("coupons-frame");
|
---|
| 2 | const newsFrame=document.getElementById("news-frame");
|
---|
| 3 | window.addEventListener('load',async function(){
|
---|
| 4 | try{
|
---|
| 5 | const response1=await fetch(`/api/coupons/getAllCoupons`);
|
---|
| 6 | const response2=await fetch(`/api/news/getAllEvents`);
|
---|
| 7 | if(response1.ok){
|
---|
| 8 | const coupons=await response1.json();
|
---|
| 9 | coupons.forEach(coupon=>{
|
---|
| 10 | const couponDiv=document.createElement("div");
|
---|
| 11 | couponDiv.classList.add("new-item");
|
---|
| 12 | couponDiv.innerHTML=`<h3>${coupon.title}</h3><p>${coupon.code}</p><p>${coupon.description}</p>`;
|
---|
| 13 |
|
---|
| 14 | couponsFrame.appendChild(couponDiv);
|
---|
| 15 | })
|
---|
| 16 | }
|
---|
| 17 | else{
|
---|
| 18 | console.log("error with coupons")
|
---|
| 19 | }
|
---|
| 20 | if(response2.ok){
|
---|
| 21 | const news=await response2.json();
|
---|
| 22 | news.forEach(event=>{
|
---|
| 23 | const eventDiv=document.createElement("div");
|
---|
| 24 | eventDiv.classList.add("new-item");
|
---|
| 25 | eventDiv.innerHTML=`<h3>${event.title}</h3><p>${event.text}</p>${event.imgSrc ? `<img src="${event.imgSrc}" style="width: 80%; height: auto;" data-attribute="${event.imgSrc}">` : ''}`;
|
---|
| 26 |
|
---|
| 27 | newsFrame.appendChild(eventDiv);
|
---|
| 28 | })
|
---|
| 29 | }
|
---|
| 30 | else{
|
---|
| 31 | console.log("error with news")
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | catch(error){
|
---|
| 35 | console.error("Error fetching data:", error);
|
---|
| 36 | }
|
---|
| 37 | }); |
---|
Note:
See
TracBrowser
for help on using the repository browser.