Skip to content

Instantly share code, notes, and snippets.

@robshep
Created June 21, 2022 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robshep/5f42b8b7f2b222d39ce4f705ba4d362e to your computer and use it in GitHub Desktop.
Save robshep/5f42b8b7f2b222d39ce4f705ba4d362e to your computer and use it in GitHub Desktop.
Load data from API and display on web page
<!DOCTYPE html>
<html style="padding: 0; margin: 0;">
<head>
<meta charset="UTF-8" />
<style>
body, html {
margin:0;
padding:0;
}
div#bg {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background-image: url(https://unsplash.com/photos/RLw-UC03Gwc/download?ixid=MnwxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNjU1ODQ3Nzcw&force=true&w=2400);
background-size: cover;
background-position: center;
}
div#statsbox {
position: fixed;
bottom: 0px;
right: 0px;
width: 250px;
height: 50px;
padding: 3px;
background-color: beige;
margin: 5px;
padding: 5px;
}
</style>
</head>
<body>
<div id="bg">
<div id="statsbox">LOADING ...</div>
</div>
<script>
function fetchAndShow() {
fetch('https://dummyjson.com/todos/random')
.then(res => res.json())
.then(data => {
document.getElementById("statsbox").innerHTML = "todo: " + data.todo
});
}
setInterval(fetchAndShow, 3500);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment