AJAX由前端向后端发送并接收数据四步骤
<script type="text/javascript">
window.onload = function()
{
document.getElementById("cal").onclick = function()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
var bmi = xmlHttp.responseText;
document.getElementById("data").innerText = bmi;
}
}
var weight = document.getElementById("w").value;
var height = document.getElementById("h").value;
var param = "weight=" + weight + "&height=" + height;
xmlHttp.open("GET","calbmi?" + param,true);
xmlHttp.send();
}
}
</script>