- Sep 11, 2005
- 17,571
- 8
- 0
I'm using Weather Underground's API for a personal project. Basically what I'm doing is pulling a location and temperature via jQuery and Ajax. This is the code so far:
What I now want to do is pull a temperature from the temp_f variable and write a conditional that changes the background color of my "color-test" div based on the result. The problem I'm running into is that temp_f is getting its data from a dynamically-generated JSON file.
How can I grab the temperature number (whatever it is) and put it into a variable that I can use for my conditional?
---
EDIT: Apologies if anything isn't clear; I'm a designer by trade, not a developer.
Code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$.ajax({
url: "http://api.wunderground.com/api/c2dc53f77e6d7223/geolookup/conditions/q/PA/Philadelphia.json",
dataType: "jsonp",
success: function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_f = parsed_json['current_observation']['temp_f'];
$("#current-temp").text('The temperature in ' + location + ' is ' + temp_f +'F.');
}
}); //end ajax call
});
</script>
</head>
<body>
<div id="current-temp"> </div>
<div id="color-test"> </div>
</body
>
</html>
What I now want to do is pull a temperature from the temp_f variable and write a conditional that changes the background color of my "color-test" div based on the result. The problem I'm running into is that temp_f is getting its data from a dynamically-generated JSON file.
How can I grab the temperature number (whatever it is) and put it into a variable that I can use for my conditional?
---
EDIT: Apologies if anything isn't clear; I'm a designer by trade, not a developer.
Last edited:
