I am trying to build a small site that will use openweathermap's api. The small site will have a zipcode number box and a submit button for searching by zipcode and it will also have a city text box and a submit button for searching by city. Here is what I have so far; I will submit the code and I will also send you to my jsfiddle .
In case the api is relevant, it can be found here .
<body>
Zipcode: <input type="number" id="myZip" min="11111" max="99999" value="00000"/>
<input type="button" value="Search by Zipcode" onclick="getWeatherbyZip()"/>
<br>
City: <input type="text" id="myCity" value="Enter city"/>
<input type="button" value="Search by City" onclick="getWeatherByCity()"/>
<script>
event.preventDefault();
function getWeatherbyZip()
{
var zipCode = function getZip();
var req = new XMLHttpRequest();
req.open("GET", "http://ift.tt/1k9itcb"+zipcode+",us&appid=fa7d80c48643dfadde2cced1b1be6ca1"+key, false);
req.send(null);
console.log(JSON.parse(req.responseText));
}
function getZip()
{
return document.getElementById("myZip").value;
}
function getWeatherByCity()
{
var city = function getCity();
var req = new XMLHttpRequest();
req.open("GET", "http://ift.tt/1jfvxJq"+city+",us&appid=fa7d80c48643dfadde2cced1b1be6ca1"+key, false);
req.send(null);
console.log(JSON.parse(req.responseText));
}
function getCity()
{
return document.getElementById("myCity").value;
}
</script>
</body>
Aucun commentaire:
Enregistrer un commentaire