Last active
February 20, 2022 10:05
-
-
Save scrouthtv/d2959110231218b267723c69132032c4 to your computer and use it in GitHub Desktop.
Example website using ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="style.css" /> | |
<script> | |
setInterval(function() { | |
var xhttp = new XMLHttpRequest(); // https://w3schools.com/xml/xml_http.asp | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
// Parse json: | |
data = JSON.parse(xhttp.responseText); | |
// Set the text to the data: | |
document.getElementById("current").innerHTML = data["leistung"]; | |
} | |
} | |
xhttp.open("GET", "solar.json"); // Optional boolean parameter defaults to true | |
xhttp.send(); | |
}, 10*1000); // Call the inner function once every 10 seconds | |
</script> | |
</head> | |
<body> | |
<div id="content"> | |
<span class="title">Aktuelle Leistung: </span> | |
<span class="data" id="current">N/A</span> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: "Century Gothic", "Arial Rounded MT Bold", sans-serif; | |
} | |
#content { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
text-align: center; | |
background-color: #ddd; | |
padding: 2em; | |
line-height: 300%; | |
-webkit-box-shadow: 3px 3px 15px 1px #000000; | |
box-shadow: 3px 3px 15px 1px #000000; | |
} | |
.title { | |
display: block; | |
font-size: 200%; | |
} | |
.data { | |
font-size: 300%; | |
} |
danke! Tut alles gut!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place
solar.json
in the same folder of the webserver.It should look like this: