From 964d5fcf351509884be71b28891ebf5743f7bc11 Mon Sep 17 00:00:00 2001 From: Divlo Date: Sun, 29 Dec 2019 01:45:04 +0100 Subject: [PATCH] Hotfix: weatherRequest getCityName -POST serialize --- php/getWeatherJson.php | 2 +- scripts/executeFunction.js | 9 +++++---- scripts/fonctions_principales.js | 5 +++-- views/function-views/weatherRequest.php | 26 +++++++++++++------------ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/php/getWeatherJson.php b/php/getWeatherJson.php index 4fe5514..fd18824 100644 --- a/php/getWeatherJson.php +++ b/php/getWeatherJson.php @@ -14,7 +14,7 @@ $_SESSION['LAST_CALL'] = date("Y-m-d h:i:s"); include 'keyVariable.php'; ini_set("allow_url_fopen", 1); -$cityName = $_COOKIE['city']; +$cityName = htmlspecialchars($_POST['city']); $url = 'https://api.openweathermap.org/data/2.5/weather?q='.$cityName.'&lang=fr&units=metric&appid='.$apiWeather; $json = file_get_contents($url); // $obj = json_decode($json); diff --git a/scripts/executeFunction.js b/scripts/executeFunction.js index b0bbdd8..5944da5 100644 --- a/scripts/executeFunction.js +++ b/scripts/executeFunction.js @@ -8,15 +8,16 @@ $(function () { } }); - $("#submitWeatherRequest").click(() => { + $("#submitWeatherRequest").click((event) => { + event.preventDefault(); const city = $('#cityName').val(); - const cityName = city.split(' ').join('+'); + const cityName = city.split(' ').join('+'); + const data = `city=${cityName}`; if(isEmptyValue(cityName)) { $('.results').html(emptyMessageError); } else { - createSessionCookie("city", cityName); - weatherRequest(); + weatherRequest(data); } }); diff --git a/scripts/fonctions_principales.js b/scripts/fonctions_principales.js index 751aec2..aaa0a16 100644 --- a/scripts/fonctions_principales.js +++ b/scripts/fonctions_principales.js @@ -12,10 +12,11 @@ * @example * Ajoute au DOM de la page dans la div .results, la météo de la ville demandée. */ -function weatherRequest() { +function weatherRequest(cityData) { $.ajax({ + type: 'POST', url: '/php/getWeatherJson.php', - type: "POST", + data: cityData, success: function(data) { try { const json = jQuery.parseJSON(data); diff --git a/views/function-views/weatherRequest.php b/views/function-views/weatherRequest.php index 18e81c1..37cd659 100644 --- a/views/function-views/weatherRequest.php +++ b/views/function-views/weatherRequest.php @@ -16,19 +16,21 @@
Météo
-
- - -
-
-
- -
-
-

-

+
+
+ + +
+
+
+ +
+
+

+

+
- +