-
Notifications
You must be signed in to change notification settings - Fork 0
/
APITester.html
51 lines (46 loc) · 1.37 KB
/
APITester.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Product App</title>
</head>
<body>
<div>
<h2>All Contacts</h2>
<ul id="contacts" />
</div>
<div>
<h2>Search by ID</h2>
<input type="text" id="contactId" size="5" />
<input type="button" value="Search" onclick="find();" />
<p id="contact" />
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
<script>
var uri = 'api/contacts';
$(document).ready(function () {
// Send an AJAX request
$.getJSON(uri)
.done(function (data) {
// On success, 'data' contains a list of contacts.
$.each(data, function (key, item) {
// Add a list item for the contact.
$('<li>', { text: formatItem(item) }).appendTo($('#contacts'));
});
});
});
function formatItem(item) {
return "(" + item.Id + ") " + item.FirstName + " " + item.LastName + ': ' + item.EmailAddress;
}
function find() {
var id = $('#contactId').val();
$.getJSON(uri + '/' + id)
.done(function (data) {
$('#contact').text(formatItem(data));
})
.fail(function (jqXHR, textStatus, err) {
$('#contact').text('Error: ' + err);
});
}
</script>
</body>
</html>