Last active
September 24, 2018 17:12
-
-
Save JeromeBATAILLE/15446e4512aac69aca3cbeee4b2acab6 to your computer and use it in GitHub Desktop.
Requete HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="fr" dir="ltr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Il fait chaud!</title> | |
</head> | |
<body> | |
<form class="" action="index.html" method="post"> | |
<p> | |
<label for="Lieu">Lieu:</label> | |
<input id="Lieu" type="text" name="lieu" placeholder="Troufignion Les Oies" size="50" maxlength="30" autofocus required/> | |
</p> | |
<div class="button"> | |
<button id="submit" type="button" onclick="myFunction()">Va chercher !</button> | |
</div> | |
</form> | |
<p id="temperature"></p> | |
<script type="text/javascript"> | |
function myFunction(){ | |
let api='http://api.openweathermap.org/data/2.5/weather?id=524901'; | |
let apiKey='&APPID=e8db502ea2aa8ae4c5756833b8a2769c'; | |
let units = '&units=metric&q='; | |
let city = document.getElementById('Lieu').value; | |
let fullApi = api+apiKey+units+city; | |
fetch(fullApi) | |
.then(function(result){ | |
return result.json(); | |
}) | |
.then (function(data){ | |
let temp = data.main.temp; | |
let temperature = "Il fait actuellement " + temp + "°C à " + city; | |
document.getElementById('temperature').innerHTML = temperature; | |
console.log(data); | |
}) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment