hjkhghopjkertteerterterterertertrtoirh
bnmbertsurhetertertertertertertertpdf'tdfg
/
home
/
ubuntu
/
bmse.net
/
Upload FileeE
HOME
<!DOCTYPE html> <html> <head> <title>My Pets</title> <meta charset="UTF-8" /> <link rel="stylesheet" href="src/styles.css" /> </head> <body> <header> <h1>Sanity + Vanilla JavaScript</h1> </header> <main> <h2>Pets</h2> <ul> <li>Loading pets…</li> </ul> <div> <pre> ¯\_(ツ)_/¯ Your data will show up here when you've configured everything correctly </pre> </div> </main> <script> let PROJECT_ID = "0trcpmwm"; let DATASET = "production"; let QUERY = encodeURIComponent('*[_type == "pet"]'); // Compose the URL for your project's endpoint and add the query let URL = `https://${PROJECT_ID}.api.sanity.io/v2021-10-21/data/query/${DATASET}?query=${QUERY}`; // fetch the content fetch(URL) .then((res) => res.json()) .then(({ result }) => { // get the list element, and the first item let list = document.querySelector("ul"); let firstListItem = document.querySelector("ul li"); if (result.length > 0) { // remove the placeholder content list.removeChild(firstListItem); result.forEach((pet) => { // create a list element for each pet let listItem = document.createElement("li"); // add the pet name as the text content listItem.textContent = pet?.name; // add the item to the list list.appendChild(listItem); }); let pre = document.querySelector("pre"); // add the raw data to the preformatted element pre.textContent = JSON.stringify(result, null, 2); } }) .catch((err) => console.error(err)); </script> </body> </html>