From de1a7af9e0b9e19a15bd881bc61baa9f1c13be13 Mon Sep 17 00:00:00 2001 From: "Dominik V. Salonen" Date: Wed, 14 Mar 2018 09:08:50 +0000 Subject: [PATCH] I guess we're closer now? --- main.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/main.js b/main.js index 10fc4c7..e1871ee 100755 --- a/main.js +++ b/main.js @@ -8,7 +8,7 @@ const button2 = document.getElementById('button2'); const button3 = document.getElementById('button3'); // Make the base URL a variable because it's easier if I ever move the site -const baseUrl = "file:///H:/Side projects/Site/"; +const baseUrl = "https://quad.moe/test/"; // Create variables that will get populated by loadContent() later var payload1; @@ -24,19 +24,15 @@ function resetButtons() { // Fetch all the page contents async function loadContent(baseUrl) { - const http1 = fetch(baseUrl + "pages/about.html"); - const http2 = fetch(baseUrl + "pages/about.html"); - const http3 = fetch(baseUrl + "pages/about.html"); + const http1 = fetch("pages/about.html"); + const http2 = fetch("pages/about.html"); + const http3 = fetch("pages/about.html"); const requests = [http1, http2, http3]; const responses = await Promise.all(requests); - for (let response of responses) { - console.log("Loaded data") - } - - return responses + return responses; } function setContent(navbutt, payload) { @@ -48,11 +44,23 @@ function setContent(navbutt, payload) { function initialContent() { // Get the HTML we need - var contents = loadContent(); - payload1 = contents[0]; - payload2 = contents[1]; - payload3 = contents[2]; + // This returns Response { type: "basic", url: "https://example.com", redirected: false... etc. + loadContent().then((res) => {console.log(res);}); + + // This returns a Promise object with : "pending" + loadContent().then((res) => {console.log(res[0].text());}); + + contents = loadContent(); + // Can't figure out how to make sure that each web request in loadContent() + // has returned proper HTML before it actually proceeds executing the rest of this funciton + + // Then store the text only for later use + payload1 = contents[0].text(); + payload2 = contents[1].text(); + payload3 = contents[2].text(); + + console.log(payload1); // Slap on all the event listeners button1.addEventListener('click', function() { @@ -67,4 +75,4 @@ function initialContent() { // And finally enable the first tab setContent(button1, payload1); -} \ No newline at end of file +}