pierwszy plik (pewnie index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="content"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
var variableToSend = 'foo';
$.post('/test2.php', {variable: variableToSend}, function (response) {
document.getElementById('content').innerHTML = response;
});
</script>
</body>
</html>
2 plik (test2.php): [wymagany php7]
$variable = $_POST['variable'] ?? '';
echo $variable