function myfunction() { const xhttp = new XMLHttpRequest(); xhttp.open("POST", "demo_phpfile.php"); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.onload = function() { document.getElementById("demo").innerHTML = this.responseText; } xhttp.send("fname=Mary"); } }