A very bad implementation of a thing looking at the websocket
This commit is contained in:
parent
a6d06350ab
commit
10e3cd0ba2
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Hello, world!</h1>
|
<h1>Hello, world!</h1>
|
||||||
<ul>
|
<p id="iteration">Iteration: {{ iteration }}<p>
|
||||||
|
<ul id="objects">
|
||||||
{% for object in objects %}
|
{% for object in objects %}
|
||||||
<li>{{ object.name }} @ {{ object.x }}, {{ object.y }}</li>
|
<li>{{ object.name }} @ {{ object.x }}, {{ object.y }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -21,7 +22,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws.onmessage = function(e) {
|
ws.onmessage = function(e) {
|
||||||
console.log("From Server:" + e.data);
|
const data = JSON.parse(e.data);
|
||||||
|
|
||||||
|
document.getElementById("iteration").innerText = `Iteration: ${data.iteration}`;
|
||||||
|
const ul = document.getElementById("objects");
|
||||||
|
while(ul.firstChild) { ul.removeChild(ul.lastChild) }
|
||||||
|
for (n in data.objects) {
|
||||||
|
const ob = data.objects[n];
|
||||||
|
const li = document.createElement("li");
|
||||||
|
li.innerText = `${ob.name} @ ${ob.x}, ${ob.y}`;
|
||||||
|
ul.append(li);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user