-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathact4.html
43 lines (41 loc) · 1.18 KB
/
act4.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
<!doctype html>
<html>
<head>
<title>City Finder</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></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>
<script>
$(document).ready(function() {
$( "#cityField" ).keyup(function() {
var url = "http://bioresearch.byu.edu/cs260/jquery/getcity.cgi?q="+$("#cityField").val();
$.getJSON(url,function(data) {
var $matches;
$matches = $("<ul>");
$.each(data, function(i,item) {
$matches.append($("<li>").append(data[i].city));
});
$("#txtHint").html($matches);
})
.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!');
})
.complete(function() { console.log("complete"); });
});
});
</script>
</body>
</html>