forked from IBM-Cloud/clouddatabases-redis-helloworld-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
36 lines (30 loc) · 801 Bytes
/
main.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
$(document).ready(function() {
function reload() {
$('.hidden').fadeOut();
$('displayOutput').empty();
$.get( '/words', function(data) {
console.log("showing", data);
var data = JSON.parse(data);
var rendered = "<ul>";
data.forEach(function(item) {
rendered = rendered + "<li>The word <b>" + item.word + "</b> is defined as <b>" + item.definition + "</b></li>";
});
rendered = rendered + "</ul>";
$('#displayOutput').html(rendered);
});
$('.hidden').fadeIn();
}
$('#add-word').submit(function(e) {
e.preventDefault();
$.ajax({
url: '/words',
type: 'PUT',
data: $(this).serialize(),
success: function(data) {
reload();
}
});
});
// load data on start
reload();
});