diff options
author | Vitaly Takmazov | 2018-09-27 22:32:27 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-09-27 22:32:27 +0300 |
commit | 5f4af8dbe4c431218c4bd186a75f50c23b8e5df0 (patch) | |
tree | ef12a02380d18bd92e331c5d29fbdc82b3918edc /juick-server/src/main/assets | |
parent | fc394e0d31e381afd6e88175b54d9ab8a4007e03 (diff) |
scripts: post over api
Diffstat (limited to 'juick-server/src/main/assets')
-rw-r--r-- | juick-server/src/main/assets/scripts.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js index 5bbbe6f2..5a5fad6b 100644 --- a/juick-server/src/main/assets/scripts.js +++ b/juick-server/src/main/assets/scripts.js @@ -677,6 +677,29 @@ ready(function () { } }); }); + postmsg.addEventListener('submit', e => { + e.preventDefault(); + let formData = new FormData(postmsg); + fetch('/api/post' + '?hash=' + document.getElementById('body').getAttribute('data-hash'), { + method: 'POST', + body: formData, + credentials: 'omit' + }).then(response => { + if (response.ok) { + response.json().then(result => { + if (result.newMessage) { + window.location = new URL(`/m/${result.newMessage.mid}`, window.location.href); + } else { + alert(result.text); + } + }); + } else { + alert('Something went wrong :('); + } + }).catch(error => { + alert(error.message); + }); + }); } document.querySelectorAll('.msg-menu').forEach(function (el) { |