diff options
author | HombreLaser <sebastian-440@live.com> | 2024-02-06 19:09:25 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2024-02-06 19:09:25 -0600 |
commit | b754555d5113f4d836b93b2b9829f07b46ab06e0 (patch) | |
tree | 3876c7f565bed84d08664ac74bfb542748beda11 /static/js/comments | |
parent | 3f1d5bbdcee41a483f9a7f36b0ef56010ac24e10 (diff) |
Add form submition in the javascript
Diffstat (limited to 'static/js/comments')
-rw-r--r-- | static/js/comments/comment_form.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/static/js/comments/comment_form.js b/static/js/comments/comment_form.js index 0d853fe..dff0803 100644 --- a/static/js/comments/comment_form.js +++ b/static/js/comments/comment_form.js @@ -1,12 +1,25 @@ class CommentForm { - constructor(domain) { + constructor(domain, post) { this.domain = domain; + this.post = post; this.form_element = document.getElementById("comment-form"); this.form_element.addEventListener("submit", this.submit); } - submit(event) { - this.form = new FormData(event.target); - console.log(this.form); + async submit(event) { + const form = new FormData(event.target); + form.append("domain", window.location.hostname); + + try { + const response = await fetch(`https://${this.domain}/${this.post}/comments`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: form + }); + const body = response.body; + } catch(error) {} } } |