HTML JS

SUBMIT HTML FORM WITHOUT RELOADING PAGE

<form id="myForm"            onsubmit="return FUNCTION()">   Name: <input type="text" name="name"/>   Email: <input type="email" name="email"/>   <input type="submit" value="Go!"/> </form>

HTML FORM

01

function ajaxpost () {    GET FORM DATA   var data = new FormData   (document.getElementById("MyForm"));     AJAX   var xhr = new XMLHttpRequest();      xhr.open("POST", "SERVER.SCRIPT");

AJAX SUBMISSION

02

  xhr.onload = function()     { console.log(this.response); };    xhr.send(data);     PREVENT HTML FORM SUBMIT      return false; };

function fetchpost () {    GET FORM DATA   var data = new FormData   (document.getElementById("MyForm"));     AJAX    fetch("0-dummy.php",      { method: "post",  body: data })

FETCH SUBMISSION

03

  .then((res) => { return res.text(); })   .then((txt) => { console.log(txt); })   .catch((err) => { console.log(err); });     PREVENT HTML FORM SUBMIT      return false; };