From a1a830a03b782b7a1abb350d20698631b2d6e559 Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Fri, 29 Oct 2021 15:30:02 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Introduced=20result=20counting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjetProgWeb/app.js | 13 ++++++++----- ProjetProgWeb/index.php | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js index 659e99a..8dfad7f 100644 --- a/ProjetProgWeb/app.js +++ b/ProjetProgWeb/app.js @@ -1,26 +1,29 @@ +let authorName = ""; + function requestToApi(author) { + authorName = author fetch(`api.php?author=${author}`) .then(response => response.json()) .then(data => displayResults(data)) } function displayResults(results) { + let count = 0 results.forEach(function(elem) { - let result = document.createElement('div') result.classList.add('result-element') - let i = 0 - elem.forEach(function(e) { let child = document.createElement(i === 0 ? 'h1' : 'p') child.innerText = e result.appendChild(child) i += 1 }) - + count += 1 document.getElementById('results').appendChild(result) - }) + let nb = document.createElement("p") + nb.innerHTML = `Nombre de résultats pour "${authorName}": ${count}.` + document.getElementById('results-count').appendChild(nb) } \ No newline at end of file diff --git a/ProjetProgWeb/index.php b/ProjetProgWeb/index.php index 2d6894e..394a2ef 100644 --- a/ProjetProgWeb/index.php +++ b/ProjetProgWeb/index.php @@ -20,6 +20,7 @@ } } ?> +