diff options
author | Vitaly Takmazov | 2018-09-25 15:48:11 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-09-25 15:48:11 +0300 |
commit | f3acdb00caaef60bd5ddfa128699f8a255261543 (patch) | |
tree | 3fdad6be0f520686317ad8ac4183a0ae751e4d8d /juick-server/src/main | |
parent | f30602aae3a581b9c9d1940c8cba99c35cebd31f (diff) |
scripts: comments over api
Diffstat (limited to 'juick-server/src/main')
-rw-r--r-- | juick-server/src/main/assets/scripts.js | 16 |
1 files changed, 16 insertions, 0 deletions
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(); |