var API_ENDPOINT = "YOUR-API-GATEWAY-HERE" 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 = "" if (typeof data['url'] === "undefined") { var player = "" } $("#posts").append(" \ " + data['id'] + " \ " + data['voice'] + " \ " + data['text'] + " \ " + data['status'] + " \ " + player + " \ "); }); }, error: function () { alert("error"); } }); } document.getElementById("postText").onkeyup = function(){ var length = $(postText).val().length; document.getElementById("charCounter").textContent="Characters: " + length; }