-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.html
72 lines (68 loc) · 2.04 KB
/
weather.html
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
<html>
<head>
<title>City Finder</title>
<script
src="http://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script>
$(document).ready(function() {
$( "#cityField" ).keyup(function() {
$.getJSON("http://bioresearch.byu.edu/cs260/jquery/getcity.cgi?q=P",function(data) {
var everything;
everything = "<ul>";
$.each(data, function(i,item) {
everything += "<li> "+data[i].city;
});
everything += "</ul>";
$("#txtHint").html(everything);
})
.done(function() { console.log('getJSON request succeeded!'); })
.fail(function(jqXHR, textStatus, errorThrown) {
console.log('getJSON request failed! ' + textStatus);
console.log("incoming "+jqXHR.responseText);
})
.always(function() { console.log('getJSON request ended!');
});
});
$("#weatherButton").click(function(e){
var value = $("#cityField").val();
console.log(value);
e.preventDefault();
$("#displayCity").text(value);
var myurl= "https://api.wunderground.com/api/427c916515dd25e8/geolookup/conditions/q/UT/";
myurl += value;
myurl += ".json";
console.log(myurl);
$.ajax({
url : myurl,
dataType : "json",
success : function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_string = parsed_json['current_observation']['temperature_string'];
var current_weather = parsed_json['current_observation']['weather'];
everything = "<ul>";
everything += "<li>Location: "+location;
everything += "<li>Temperature: "+temp_string;
everything += "<li>Weather: "+current_weather;
everything += "</ul>";
$("#weather").html(everything);
}
});
});
});
</script>
</head>
<body>
<form>
Enter A Utah City: <input type="text" id="cityField" value=""><br>
Suggestion: <span id="txtHint">Empty</span>
<input id="weatherButton" type="submit" value="Submit">
</form>
<p>City</p>
<textarea id="displayCity">No City</textarea>
<p>Current Weather</p>
<div id="weather">No weather</div>
</body>
</html>