-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayweather.js
74 lines (66 loc) · 2.59 KB
/
displayweather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$(document).ready(function() {
var year = '2010',
month = '04',
day = '23',
station_id = 'USW00013723';
$('td.year div').click(function() {
year = $(this).attr('class');
updateChoices();
});
$('td.month div').click(function() {
month = $(this).attr('class');
updateChoices();
});
$('td.day div').click(function() {
day = $(this).attr('class');
updateChoices();
});
function updateChoices() {
$('td.year div').css({'background-color' : '#ffffff'});
$('td.year .'+year).css({'background-color' : '#ff0000'});
$('td.month div').css({'background-color' : '#ffffff'});
$('td.month .'+month).css({'background-color' : '#ff0000'});
$('td.day div').css({'background-color' : '#ffffff'});
$('td.day .'+day).css({'background-color' : '#ff0000'});
$('td.station div').css({'background-color' : '#ffffff'});
$('td.station .'+station_id).css({'background-color' : '#ff0000'});
$('table.results span.date').text(year + '-' + month + '-' + day);
$.ajax({
url : 'getstation.php?id=' + station_id,
dataType : 'json',
success : function(station) {
$('table.results td.name').text(station.name);
$('table.results td.station_id').text(station.id);
$('table.results td.lat').text(station.lat);
$('table.results td.lon').text(station.lon);
$('table.results td.elev').text(station.elev);
$('table.results td.state').text(station.state);
}
});
$.ajax({
url : 'getweather.php?id=' + station_id + '&year=' + year + '&month=' + month + '&day=' + day,
dataType : 'json',
success : function(weather) {
$('table.results td.temp').text(weather.temp);
$('table.results td.prcp').text(weather.prcp);
}
});
}
$.ajax({
url : 'getstation.php',
dataType : 'json',
success : function(stations) {
for (i=0; i<stations.length; ++i) {
$('table.calendar td.station').append($('<div class="'+stations[i].id+'">'+stations[i].name+'</div>'));
}
$('td.station div').click(function() {
station_id = $(this).attr('class');
updateChoices();
});
updateChoices();
},
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
});