'How do I get input from the DOM and then send a response back in node.js
Basically I'm trying to have the user be able to input something into a form, for it to be sent back to the server so I can then process it and then send back a response that updates the DOM to show the result. I've tried figuring out jQuery and cheerio but I'm just confused and not sure exactly how I can do what I want
Solution 1:[1]
i think you must make HTTP Request POST to finish it, i have an article that can guide you, and i hope it helps
Solution 2:[2]
Just to get you started:
let data = Object.fromEntries(new FormData(document.querySelector("form")))
fetch(url, {
body: JSON.stringify(data)
}).then(r => r.json().then(responseData => {
document.querySelector("p").innerText = responseData.message
}))
Then you have to work out the backend code and adjust what I posted here to suit your needs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Reza Alpadizami |
| Solution 2 | pguardiario |
