PHP JS

AJAX CALL TO PHP - A SIMPLE EXAMPLE

1) HTML

<form onsubmit="return ajaxpost()">   <input type="email" id="email"      required/>   <input type="submit" value="Go!"/>  </form> <div id="response"></div>

2) JAVASCRIPT

function ajaxpost () {   // FORM DATA   var data = new FormData();  data.append("email", document.  getElementById("email").value);     // AJAX POST   var xhr = new XMLHttpRequest();   xhr.open("POST", "SCRIPT.PHP");   xhr.onload = function () {     document.getElementById     ("response").innerHTML =     this.response;   };   xhr.send(data);   return false; }

3) PHP

// DO FORM PROCESSING print_r($_POST); echo "USER SAVED";