Skip to content

Instantly share code, notes, and snippets.

@MkLHX
Last active October 10, 2018 13:32
Show Gist options
  • Save MkLHX/83f2ef387e5f0a76894384fc282340da to your computer and use it in GitHub Desktop.
Save MkLHX/83f2ef387e5f0a76894384fc282340da to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Document</title>
</head>
<body>
<h1>Stream your Javascript weather!</h1>
<input type="text" name="searchBar" id="searchBar"/>
<button id="go">Go!</button>
<img src="#" alt="">
<script>
var req = new XMLHttpRequest();
var bp ='';
var weather = document.getElementById("weather");
document.getElementById("go").onclick = function(){
var city = document.getElementById("searchBar").value;
req.open('GET', 'http://api.openweathermap.org/data/2.5/weather?q=' + city + ',uk&appid=40bfa73b427890ed34c44716159753ff&units=metric', false);
req.send(null);
if (req.status == 200) {
dump(req.responseText);
}
result = JSON.parse(req.responseText);
var icon = result.weather[0].icon;
var value = document.createElement("DIV");
var link = '"http://openweathermap.org/img/w/'+icon+'.png"';
var data = document.createTextNode(result.main.temp+'°C'+' à '+city);
value.appendChild(data);
document.getElementsByTagName("img")[0].setAttribute("src",'http://openweathermap.org/img/w/'+icon+'.png');
document.body.appendChild(value);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment