Formular POST mit JavaScript

  • Beitrags-Autor:
  • Beitrags-Kategorie:Webdesign
var xhr = new XMLHttpRequest();
xhr.open("POST", "/service", true);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var a = document.getElementById("post_param_a").value;
var b = document.getElementById("post_param_b").value;
var params = "a=" + a + "&b=" + b;
xhr.send(params);
xhr.onload = function() {
    var r = xhr.responseText;
    document.getElementById("response_text").innerText = r;
}