API Homework

Finally getting the hang of this. Thank you for going over it again Master P, really helped.
For anyone in the class who missed it and is looking for it here is what we went over in the review friday:

http://cssdeck.com/labs/ke0mp2in

Here is the code, I got my own key and pulled the weather forecast for my Home town of Wagram North Carolina:

Raw Data link:

http://api.wunderground.com/api/dc48a9b9b5d76b6a/forecast/q/NC/Wagram.json

Script:

<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>JSON WITH API: Astronomy 1</title>

<script type=”text/javascript” src=”js/jquery-1.10.2.min.js”></script>

<script type=”text/javascript”>

/*Standard request URL format =
http://api.wunderground.com/api/b79e3040f6431025/features/settings/q/query.format
where
features=> type of data, here astronomy
settings=> lang or personal data
query=> location of data
*/

$(document).ready(function(){
$.ajax({
url: “http://api.wunderground.com/api/dc48a9b9b5d76b6a/forecast/q/NC/Wagram.json&#8221;,
dataType : “jsonp”, //jsonp for cross-origin files
success : function(parsed_json) {
console.log(‘success!!’);
//each nested object goes in []
var wagramWeather = parsed_json[‘forecast’][‘txt_forecast’][‘forecastday’][1][‘fcttext’];
var wagramWeatherday2 = parsed_json[‘forecast’][‘txt_forecast’][‘forecastday’][3][‘fcttext’];

$(“#container”).append(“Here is the forecast for the place I was born and raised(Wagram, NC): “+wagramWeather);

$(“#container2”).append(“Wednesday in Wagram will be: “+wagramWeatherday2);

} //end of success
}); //end of ajax
}); //end of doc ready

 
</script>

</head>

<body>
<section id=”container”>
<
</section>
<section id=”container2″>

</section>
</body>
</html>

Leave a comment

Filed under Homework

Leave a comment