-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyClosetAPI.html
77 lines (68 loc) · 3.7 KB
/
MyClosetAPI.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
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<title>MyClosetAPI</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
</head>
<body>
<div>Count: <input type="text" value="0" id="txtCount" /></div>
<div>Filter: <input type="text" id="txtFilter" /></div>
<input type="button" id="btnGetCars" value="Get Cars" />
<input type="button" id="btnClear" value="Clear" />
<input type="button" id="btnGetCustomers" value="Get Customers" />
<ol id="ulList" class="list-group"></ol>
<script type="text/javascript">
$(document).ready(function () {
var ulList = $('#ulList');
var count = $('#txtCount');
var filter = $('#txtFilter');
//===================================================================================================
// Get a list of random cars from an API
//===================================================================================================
$('#btnGetCars').click(function () {
ajax("Cars", { "count": count.val(), "filter": filter.val() }, function (data) {
ulList.empty();
$.each(data, function (index, val) {
ulList.append('<li class="list-group-item">' + (val.Year + ', ' + val.Make + ' ' + val.Model).replace(filter.val(),'<span style="background-color:yellow;">' + filter.val() + '</span>') + '</li>')
});
});
});
//===================================================================================================
// Get a list of customers from the database using an API
//===================================================================================================
$('#btnGetCustomers').click(function () {
ajax("getCustomersByFilter", { "count": count.val(), "filter": filter.val() }, function (data) {
ulList.empty();
$.each(data, function (index, val) {
ulList.append('<li class="list-group-item"><img src="https://robohash.org/' + val.EmailAddress + '.png" width="50" height="50" />' + (val.EmailAddress + ': ' + val.FirstName + ' ' + val.LastName).replace(filter.val(),'<span style="background-color:yellow;">' + filter.val() + '</span>') + '</li>')
});
});
});
//===================================================================================================
// Button to clear the fields
//===================================================================================================
$('#btnClear').click(function () {
ulList.empty();
count.val('0');
filter.val('');
});
//===================================================================================================
// Generic method for AJAX calls
//===================================================================================================
function ajax(method, data, fn) {
$.ajax({
type: 'POST',
url: 'MyGuitarShopAPI.asmx/' + method,
dataType: 'json',
data: data,
success: fn
});
}
});
</script>
</body>
</html>