diff --git a/index.html b/index.html index 33c1580..443a427 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,10 @@ Mini Weather App - + + +
@@ -13,8 +15,10 @@

Weather App

- + + +
@@ -23,7 +27,7 @@

Weather App

-

+
@@ -45,7 +49,6 @@

- - + diff --git a/js/main.js b/js/main.js index da8a934..0798514 100644 --- a/js/main.js +++ b/js/main.js @@ -1 +1,41 @@ -/* Javascript goes here! */ + console.log("helloworld!"); +$(document).ready( function(){ + console.log('I am ready for this stuff'); + // eventually this should be triggered by search button + $("form").submit(function(e) { + e.preventDefault(); + requestWeatherData(); +}); +}); + +function requestWeatherData() { + // this should request live weather data from API + // eventually based on what the user searches + console.log('Requesting Data'); + + $.ajax({ + method: 'GET', + url: 'http://api.openweathermap.org/data/2.5/weather', + data: $("form").serialize(), + dataType: 'json', + success: onSuccess, + error: onError, + }); +} + +function onSuccess(data) { + // TODO: code me + var imgSource = `http://openweathermap.org/img/w/${data.weather[0].icon}.png`; + + $('.temperature').html(data.main.temp); + $('.description').html(data.weather[0].description); + $('.icon-container').html(``); + console.log('Request successful'); + console.log(data); +} + +function onError() { + // TODO: code me + $('.city-error').css('display', 'block'); + console.log('Oops its broken'); +};