<html>
the <head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="jquery-3.3.1min.js"></script>
<script src="js.js"></script>
</head>
the <body>
<h1>Press</h1>
<?php
echo 'Data received - '.$_POST['text'];
?>
</body>
</html>
$(function() {
$('h1').click(function () {
$.ajax({
url: 'index.php', /* Where will the request */
method: 'post', /* transmission Method (post or get) */
/* The data type in the response (xml, json, script, html). */
data: {text: 5}, /* Parameters passed in the request. */
success: function(data){ /* function to be executed after a successful request. */
console.log(data); /* The data variable contains the response from index.php. */
}
});
});
});
<html>
the <head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="jquery-3.3.1min.js"></script>
<script src="js.js"></script>
</head>
the <body>
<h1>Press</h1>
Data received - 5
</body>
</html>
Find more questions by tags WAMPHTMLjQueryJavaScriptAJAX