<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
    var a = document.getElementById("name").value;
    var b = document.getElementById("message").value;
    var postdata = "name=a&message=b"; //Probably need the escape method for values here, like you did
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("POST", "/chat/backend-input.php", true);
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhttp.send(postdata);
}
</script>
<form onsubmit="loadDoc()">
Name: <input type="text" name="name" id="name"><br>
Message: <input type="text" name="message"><br>
<input type="submit"></input>
</form>
Why does this code not work? Have I done something wrong, when I press the submit button it does not POST the data from the form
Can someone explain where I have gone wrong?
Edit: Instead of outputting what is in the form it's outputting a and b.
 
    