JS

HOW TO POST FORM DATA WITH JAVASCRIPT FETCH

<form onsubmit="return sendData()">   <input type="text" id="name"                required/>    <input type="email" id="email"                required/>     <input type="submit" value="Go!"/> </form>

DUMMY HTML FORM

01

function sendData () {   GET FORM DATA   var data = new FormData();   data.append("name", document.     getElementById("name").value);   data.append("email", document.     getElementById("email").value);

FETCH POST FORM DATA

02

  INIT FETCH POST   fetch("URL",     { method: "POST", body: data })

  SERVER RESPONSE   .then((res) => { return res.text(); })   .then((res) => { alert(txt); });   return false; }