main.js 534 B

123456789101112131415161718192021222324
  1. console.log("JS Loaded")
  2. const url = "127.0.0.1:3001"
  3. var inputForm = document.getElementById("inputForm")
  4. inputForm.addEventListener("submit", (e)=>{
  5. //prevent auto submission
  6. e.preventDefault()
  7. const formdata = new FormData(inputForm)
  8. fetch(url,{
  9. method:"POST",
  10. body:formdata,
  11. }).then(
  12. response => response.text()
  13. ).then(
  14. (data) => {console.log(data);document.getElementById("serverMessageBox").innerHTML=data}
  15. ).catch(
  16. error => console.error(error)
  17. )
  18. })