From 05a37c6d7df901a140d66c60949228708914a744 Mon Sep 17 00:00:00 2001 From: vautrin33u <vautrin33u@etu.univ-lorraine.fr> Date: Mon, 20 Dec 2021 12:46:34 +0100 Subject: [PATCH] ajout photos --- Service.php | 4 +++- suggestion.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Service.php b/Service.php index ecfd3f4..9a6e34f 100644 --- a/Service.php +++ b/Service.php @@ -59,7 +59,9 @@ if (isset($decoded['images'])){ $nom = strtr( $nom, $accents ); foreach (array_filter(glob('Photos/*.jpg'), 'is_file') as $file){ if ('Photos/'.$nom.'.jpg' == $file){ - echo '<img src="data:image/jpg;base64,'.base64_encode(file_get_contents($file)).'">'; + echo $file; + }else{ + echo ''; } } unset($decoded['images']); diff --git a/suggestion.js b/suggestion.js index 3520c05..1913139 100644 --- a/suggestion.js +++ b/suggestion.js @@ -43,9 +43,23 @@ function afficheRecettes(recette){ } const search = recette[i].titre; + const input = { images : search }; + + + var xhr = new XMLHttpRequest(); + + xhr.open('POST', "Service.php", true); + + xhr.onload = () => { + if (xhr.response != null){ + image.src = xhr.responseText; + } + }; + + xhr.send(JSON.stringify(input)); // Ajout à la div de recettes div.append(titre); -- GitLab