updated number
This commit is contained in:
parent
1bdfd6056f
commit
4ee7e48d77
1 changed files with 17 additions and 13 deletions
|
@ -2,24 +2,27 @@
|
||||||
{% extends "/_base.html"%}
|
{% extends "/_base.html"%}
|
||||||
{% block head%}
|
{% block head%}
|
||||||
<script>
|
<script>
|
||||||
|
const url = "wss://api.trimill.xyz/number";
|
||||||
|
let ws = undefined;
|
||||||
|
|
||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
var xhr = new XMLHttpRequest();
|
try {
|
||||||
xhr.open("GET", "https://api.trimill.xyz/number");
|
ws = new WebSocket(url);
|
||||||
xhr.send();
|
ws.addEventListener("message", msg => {
|
||||||
xhr.onload = () => {
|
document.getElementById("error").textContent = "";
|
||||||
document.getElementById("number").innerHTML = xhr.responseText;
|
document.getElementById("number").textContent = msg.data;
|
||||||
}
|
console.log(msg);
|
||||||
xhr.onerror = () => {
|
});
|
||||||
document.getElementById("number").innerHTML = "Error loading number."
|
} catch(e) {
|
||||||
|
document.getElementById("error").textContent = "Error connecting to server: " + e.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function makegoup() {
|
function makegoup() {
|
||||||
var xhr = new XMLHttpRequest();
|
try {
|
||||||
xhr.open("POST", "https://api.trimill.xyz/number");
|
ws.send("inc");
|
||||||
xhr.send();
|
} catch(e) {
|
||||||
xhr.onload = () => {
|
document.getElementById("error").textContent = "Error connecting to server: " + e.toString();
|
||||||
document.getElementById("number").innerHTML = xhr.responseText;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -29,4 +32,5 @@
|
||||||
<div>
|
<div>
|
||||||
<input type="button" value="Make go up" id="button" onclick="makegoup();" />
|
<input type="button" value="Make go up" id="button" onclick="makegoup();" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="error" id="error"></div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue