diff options
author | HombreLaser <sebastian-440@live.com> | 2024-02-08 18:21:12 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2024-02-08 18:21:12 -0600 |
commit | e91a86a714686a22149b55c9d5f0210cec8fef52 (patch) | |
tree | ac7212b106dac7a357b3f5a1a834b17f431f07bc /static/js/controllers | |
parent | a4dbf1cd8d0769b1ff1e0d99217f92b28b92e0d4 (diff) |
Add CORS
Diffstat (limited to 'static/js/controllers')
-rw-r--r-- | static/js/controllers/comments_controller.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/static/js/controllers/comments_controller.js b/static/js/controllers/comments_controller.js new file mode 100644 index 0000000..611b2ee --- /dev/null +++ b/static/js/controllers/comments_controller.js @@ -0,0 +1,31 @@ +export class CommentsController { + constructor(domain, post) { + this.domain = domain; + this.post = post; + this.parser = new DOMParser(); + this.form_element = document.getElementById("comment-form"); + this.form_element.addEventListener("submit", this.submit.bind(this)); + } + + 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 response_page = this.htmlFromResponse(response.body); + } catch(error) {} + } + + htmlFromResponse(body) { + return this.parser.parseFromString(body, "text/html"); + } + } + |