Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let request = new XMLHttpRequest();
- request.open(
- "GET",
- "https://www.unisport.dk/api/products/batch/?list=179249,179838,174351,180011,180020,178429"
- );
- request.onload = function() {
- let data = JSON.parse(request.responseText).products;
- console.log(data);
- renderHTML(data);
- currencyFormat(data);
- };
- request.send();
- function renderHTML(data) {
- let slider = document.getElementById("slider");
- for (let product of data) {
- //you dont need to pass the whole data since you use only price, pass only price
- let converted_price = currencyFormat(product.price);
- slider.innerHTML +=
- '<div class="product">' +
- '<img class="item-image" src="' +
- product.image +
- '" alt="image" width="100" height="100">' +
- '<div class="product-description">' +
- //notice here
- converted_price +
- "</div>" +
- product.name +
- '<div class="size">' +
- '<select name="size"><option value="">Choose Size</option><option value="'+product.sizes+'"</option></select></div>'+
- "</div>" ;
- }
- }
- function currencyFormat(price) {
- let formatter = new Intl.NumberFormat("da-DK", {
- style: "currency",
- currency: "DKK",
- minimumFractionDigits: 2
- });
- let formatted = formatter.format(price);
- // console.log(formatted);
- return formatted;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement