Tak jsem pro tebe sesmolil příklad. Jen doufám, že zas nebudeš psát něco jinýho.
index.htm
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<h2>Test</h2>
<button type="button" onclick="loadDoc()">Request</button>
<p id="demo"></p>
<script>
var val = 'string';
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("POST", "test.php", true);
xhttp.send("val=".val);
}
</script>
</body>
</html>
test.php
<?php
if ($_POST["val"]="string") echo "nejaky ysledek";
?>