-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
63 lines (49 loc) · 1.56 KB
/
scripts.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var API_ENDPOINT = "https://bq8sm3829g.execute-api.ap-south-1.amazonaws.com/dev"
document.getElementById("sayButton").onclick = function(){
var inputData = {
"voice": $('#voiceSelected option:selected').val(),
"text" : $('#postText').val()
};
$.ajax({
url: API_ENDPOINT,
type: 'POST',
data: JSON.stringify(inputData) ,
contentType: 'application/json; charset=utf-8',
success: function (response) {
document.getElementById("postIDreturned").textContent="Post ID: " + response;
},
error: function () {
alert("error");
}
});
}
document.getElementById("searchButton").onclick = function(){
var postId = $('#postId').val();
$.ajax({
url: API_ENDPOINT + '?postId='+postId,
type: 'GET',
success: function (response) {
$('#posts tr').slice(1).remove();
jQuery.each(response, function(i,data) {
var player = "<audio controls><source src='" + data['url'] + "' type='audio/mpeg'></audio>"
if (typeof data['url'] === "undefined") {
var player = ""
}
$("#posts").append("<tr> \
<td>" + data['id'] + "</td> \
<td>" + data['voice'] + "</td> \
<td>" + data['text'] + "</td> \
<td>" + data['status'] + "</td> \
<td>" + player + "</td> \
</tr>");
});
},
error: function () {
alert("error");
}
});
}
document.getElementById("postText").onkeyup = function(){
var length = $(postText).val().length;
document.getElementById("charCounter").textContent="Characters: " + length;
}