From 23abdc9488ef84d852a5029340a2ac3c66943d99 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 23 Mar 2019 13:43:02 +0100 Subject: Fetch rooms from database using ajax/json. --- public/index.html | 4 ++++ public/js/app.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/public/index.html b/public/index.html index abb347e..6e6333f 100644 --- a/public/index.html +++ b/public/index.html @@ -7,5 +7,9 @@

Ramaskrik 2019

+
+ +
+
diff --git a/public/js/app.js b/public/js/app.js index 6f30a1f..6148be4 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -16,6 +16,14 @@ along with this program. If not, see . */ +function fetch_rooms(data_done) { + let req = new XMLHttpRequest() + req.addEventListener("load", data_done) + req.open("GET", "http://localhost:8000/rooms") + req.responseType = "json" + req.send() +} + function load_screenings(data_done) { let req = new XMLHttpRequest() req.addEventListener("load", data_done) @@ -42,10 +50,24 @@ function log_film(film) { } window.addEventListener("load", function() { + /* load_screenings(function() { this.response.forEach(function(film) { log_film(film) }) }) + */ + fetch_rooms(function() { + let table = document.getElementById("screening-table") + let row = document.createElement("tr") + table.appendChild(row) + + this.response.forEach(function(room) { + console.log(room["name"]) + let item = document.createElement("th") + item.innerHTML = room["name"] + row.appendChild(item) + }) + }) console.log("Holahey!") }) -- cgit v1.2.3