Submit POST Form Data With JavaScript
Introduction
I'm working on a personal browser extension1 for my Grimoire2. I need it to send data to the local server that provides the backend3. This is how I'm doing that:
HTML
Submit
waiting...
Output
waiting...
JavaScript
const sender = document.;
sender.;
Notes
-
The code on this page is live. If you click the Submit button, it'll run. Assuming the service it's connected to is running, you'll see a response update the
element.
-
The
sendData
function is attached to theclick
handler of the#submit-button
. -
When
sendData
is triggered it sends aPOST
request tohttps://echo.hoppscotch.io
with the parameters defined inbodyData
-
The JSON response is stringified and output in
when it's returned. The payload is an echo which shows the original parameters along with some metadata.
-- end of line --
Footnotes
The idea is to add functionality to the browser so I can open a little window on any page and use it to make a bookmark, grab a quote, or collect videos directly into my Grimoire.
Some call it a notes app. I call it a book of magic.
The backend I'm building that will let me add a bunch of automation to my Grimoire.