AJAX
AJAX POST (PHP)
text.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text</title>
<script type="text/javascript">
function saveTxt(){
var theTxt = "Hallo";
var toUser = "you";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("POST", "processtext.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("sometxt=" + theTxt + "&moretxt=" + toUser);
}
</script>
</head>
<body>
<button onclick="saveTxt();">Run script</button>
<div id="demo"></div>
</body>
</html>
processtext.php:
if($_REQUEST["sometxt"]){
$exampletext = $_REQUEST["sometxt"];
$secondstring = $_REQUEST["moretxt"];
echo "The text: ".$exampletext." ".$secondstring;
}
?>
More info:
AJAX - Send a Request To a Server (W3Schools)