<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>calc</title>
</head>
<body>
<input type="text" id="num_a" name="num_a">* <input type="text" id="num_b" name="num_b"> =
<input type="text" id="result" name="result">
<p>
<button id="btncalc" onclick="doAJAX()"> AJAX compute</button>
</p>
</label>
<hr>
<form action="#" method="get">
<input type="text" id="num_1" name="num_1"><label for="num_1"> * <label for="num_2"></label><input type="text" id="num_2" name="num_2"> = <input type="text" id="res" name="res" value="{{ res if res else ''}}"><label for="res"></label>
<p>
<input type="submit" value="计算">
</p>
</label>
</form>
</body>
</html>
<script>
function doAJAX() {
{#alert('ok');#}
var xhr = new XMLHttpRequest();
var a = document.getElementById('num_a').value;
var b = document.getElementById('num_b').value;
console.log(a);
console.log(b);
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200){
document.getElementById('result').value = xhr.responseText;
}
}
xhr.open('GET','/ajax_calc?a=' + a + '&b=' + b);
xhr.send();
}
</script>
ajax-computer
最新推荐文章于 2023-03-24 15:25:14 发布