Added webpage to display network contents

This commit is contained in:
Danielv123 committed 2016-08-23 19:31:27 +02:00
1 parent 8ea74821b4
commit 410b3e5e53
4 files changed
+97 -8

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
contents = {
"iron-plate":100,
"copper-plate":7312,
}
function drawcontents(data) {
keys = Object.keys(data);
result = "<table>";
for(i = 0;i < data.length; i++) {
result = result + "<tr><td>" + data[i].name + "</td><td>" + data[i].count + "</td></tr>";
}
result = result + "</table>"
document.getElementById("contents").innerHTML = result;
}
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
data = JSON.parse(xmlhttp.responseText);
drawcontents(data);
}
}
xmlhttp.open("GET", "inventory", true);
xmlhttp.send();
}, 500)