var req = new XMLHttpRequest();
function askServer() {
var number1 = document.getElementById("number1").value;
var number2 = document.getElementById("number2").value;
var dataToSend = "?number1=" + number1 + "&number2=" + number2;
req.open("GET", "server.php" + dataToSend, true);
req.onreadystatechange = handleServerResponse;
req.send(null);
document.getElementById("result").innerHTML=
"The request has been sent.";
}
function handleServerResponse() {
alert("mes");
if ((req.readyState == 4) && (req.status == 200)) {
var result = req.responseText;
document.getElementById("result").innerHTML =
"The answer is " + result + ".";
}
}
<?php
$num1 = $_GET['number1'];
$num2 = $_GET['number2'];
$sum = $num1 + $num2;
echo($sum);
?>
<!DOCTYPE>
<html lang="ru">
<head>
<title>Test</title>
<meta charset="utf-8">
<link href="styles.css" rel="stylesheet">
<script src="JS.js"></script>
</head>
<body>
<form>
<fieldset>
<legend>Test</legend>
<input id="number1" type="number">
<input id="number2" type="number">
<button onclick="askServer()">Умножить</button>
</fieldset>
<output id="result"></output>
</form>
</body>
</html>