forked from htnani/Assignments-2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·42 lines (38 loc) · 1.29 KB
/
script.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
(function ($) {
apiUrl = 'https://YOUR-API-HOST/test/serverless-controller';
tableName = 'shopping-list';
// Load Table items when page loads
// Call API Gateway GET Item
$.ajax({
url: apiUrl + "?" + $.param({TableName: tableName}),
type: 'GET',
crossDomain: true,
success: function (result) {
$.each(result.Items, function (i, item) {
$('#items').append('<li>' + item.ThingId.S + '</li>');
});
},
error: function (result) {
$('#error').toggle().append('<div>' + result.statusText + '</div>');
}
});
// Form submit
$("#form").submit(function (event) {
event.preventDefault();
ThingId = $('#ThingId').val();
// Call API Gateway POST Item
$.ajax({
url: apiUrl,
data: JSON.stringify({TableName: tableName, Item: {ThingId: {S: ThingId}}}),
type: 'POST',
crossDomain: true,
success: function (result) {
$('#ThingId').val('');
$('#items').append('<li>' + ThingId + '</li>');
},
error: function (result) {
$('#error').toggle().append('<div>' + result.statusText + '</div>');
}
});
});
})(jQuery);