api

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.1 kB
4
Indexable
Never
async function renderInfo() {
    let url = "https://mocki.io/v1/08021574-f46d-4231-bca1-ffd6a3315b7c";

    fetch(url, {
        method: "GET",
    })
        .then((response) => response.json())
        .then((response) => {
            let html = "";
            response.data.forEach((info) => {
                html += `<div>
                            <img src="${info.image}" />
                            <h1>${info.title}</h1>
                            <p>${info.content}</p>
                         </div>`;
            });

            let container = document.getElementById("services--slider");
            container.innerHTML = html;
        })
        .catch((error) => {
            console.error(error);

            let container = document.getElementById("services--slider");
            html = `<div>
                        <img src="https://tinyurl.com/2mmoqtkv" />
                        <h1>Error</h1>
                        <p>Error</p>
                    </div>`;
            container.innerHTML = html;
        });
}

renderInfo();