From 9e237adc1936cba00b8b87abffb6c9b0ae73613e Mon Sep 17 00:00:00 2001 From: karl Date: Tue, 10 Dec 2019 15:18:02 +0100 Subject: [PATCH] Add alert box which does another request to HTML --- MoviesClient/web/index.html | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/MoviesClient/web/index.html b/MoviesClient/web/index.html index e37bde6..04bbead 100644 --- a/MoviesClient/web/index.html +++ b/MoviesClient/web/index.html @@ -9,28 +9,39 @@ const MOVIES_RESOURCE_URL = "http://localhost:8080/movieservice/resources/movie"; - let loadNews = function () { - let options = { - mode: "cors", - headers: { - "Accept": "application/json", - "Authorization": "Basic " + btoa("moviesuser:topsecret") - } - }; + const options = { + mode: "cors", + headers: { + "Accept": "application/json", + "Authorization": "Basic " + btoa("moviesuser:topsecret") + } + }; + let loadNews = function () { // Studios: ID dranhängen -> 2. Aufruf -> Alert dranhängen fetch(MOVIES_RESOURCE_URL, options) .then(response => response.json()) .then(function (moviesList) { let html = moviesList.map(movie => `

${movie.title}

-

${movie.description}

`) +

${movie.description}

+ `) .join(""); document.getElementById("content").innerHTML = html; }) .catch(error => document.getElementById("content").innerHTML = `Error: ${error}`); }; + + let displayDetails = function (id) { + fetch(MOVIES_RESOURCE_URL + "/" + id, options) // TODO: Ugly URL building + .then(response => response.json()) + .then(function (movie) { + alert(movie.length) + }) + .catch(error => document.getElementById("content").innerHTML = `Error: ${error}`); + }; + document.addEventListener("DOMContentLoaded", loadNews);