From 6a81961f59c10181e064ac9e51422a29830c0bf7 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 14 Jun 2017 23:14:57 -0700 Subject: [PATCH] Wrote front-end for Hello Location; Made Javascript generate request table --- resources/sandbox/sandbox.js | 63 +++++++++++++----------------------- sandbox.html | 14 +------- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/resources/sandbox/sandbox.js b/resources/sandbox/sandbox.js index e256de1..49c0eb3 100644 --- a/resources/sandbox/sandbox.js +++ b/resources/sandbox/sandbox.js @@ -3,49 +3,30 @@ https://www.youtube.com/watch?v=h0ZUpPiV1ac */ window.onload = function(){ - $.get("./data/players.json", function(data){ - console.log(data); - document.getElementById('atom-players').innerHTML = JSON.stringify(data); - }); - $.get("https://server.figytuna.com:8080/ali/hello/world", function(data){ - document.getElementById('hello-world').innerHTML = data; - }); - - $.get("https://server.figytuna.com:8080/ali/hello/data", function(data){ - document.getElementById('hello-data').innerHTML = data; - }); - $.get("https://server.figytuna.com:8080/ali/hello/players", function(data){ - document.getElementById('hello-players').innerHTML = data; - }); - /* - let http = new XMLHttpRequest(); - - http.onreadystatechange = function(){ - const finalState = 4; - const idealStatus = 200; - - if(http.readyState == finalState && http.status == idealStatus){ - console.log(JSON.parse(http.response)); - } + const serverPath = "https://server.figytuna.com:8080/ali/hello/"; + const pages = [ + "world", + "data", + "players", + "location" + ] + //Generate HTML table + for (pagePath in pages){ + //Adds new table row based on the data request + const $newTableRow = $("" + + "Hello " + pagePath + "" + + "" + + ""); + //Appends new table row to table + $("#hello-table").after($newTableRow); } - const method = "GET"; - const filepath = "data/players.json"; - const isASYNC = true; - http.open(method, filepath, isASYNC); - http.send(); - */ - + //Gets Table data from server + for (pagePath in pages){ + $.get(serverPath + pagePath, function(data){ + document.getElementById("hello-" + pagePath).innerHTML = data; + }); + } } - -/* READY STATES - -0 - Request not initialized -1 - Request has been set up -2 - Request has been sent -3 - Request is in process -4 - Request is complete - -*/ diff --git a/sandbox.html b/sandbox.html index 23b363b..77e05d8 100644 --- a/sandbox.html +++ b/sandbox.html @@ -19,23 +19,11 @@

ButtonPresents Stuff

- +
- - - - - - - - - - - -
Data Requests Data Responses
Hello World
Hello Data
Hello Players