-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
42 lines (38 loc) · 1.33 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-GW-URL/test/ccbda-dynamoDB-python-CRUD';
tableName = 'ccbda-example';
// 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);