From f3acdb00caaef60bd5ddfa128699f8a255261543 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 25 Sep 2018 15:48:11 +0300 Subject: scripts: comments over api --- juick-server/src/main/assets/scripts.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'juick-server') diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js index 289ccb43..19383e94 100644 --- a/juick-server/src/main/assets/scripts.js +++ b/juick-server/src/main/assets/scripts.js @@ -342,6 +342,22 @@ function showCommentForm(mid, rid) { return false; } submitButton.disabled = true; + e.preventDefault(); + let formData = new FormData(form); + fetch('/api/comment' + '?hash=' + document.getElementById('body').getAttribute('data-hash'), { + method: 'POST', + body: formData, + credentials: 'omit' + }).then(response => { + if (response.ok) { + return response.json(); + } + }).then(reply => { + window.location.href = new URL(`${mid}#${reply.rid}`, window.location.href); + window.location.reload(true); + }).catch(error => { + alert(error.message); + }) }); } reply.querySelector('.msg-comment textarea').focus(); -- cgit v1.2.3