用Ajax(javascript、XMLHttpRequest等)技术实现:前端页面输入两个数值后端服务完成两个数值相加在前端页面显示从后端服务取得的两个数值相加后的结果
2 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
<script type="text/javascript"> function AddNumbers() { // Create an instance of the HTTP Request Object var xmlHttp = new XMLHttpRequest(); var value1 = document.getElementById("txtValue1").value; var value2 = document.getElementById("txtValue2").value; // Specify HTTP POST so that parameters can be passed in // request body xmlHttp.open("POST", "add.aspx", false); // Send the parameters in CSV format xmlHttp.send(value1 + "," + value2); var result = document.getElementById("spanResult"); // Use result of calculation from server result.innerHTML = xmlHttp.responseText; } </script> ... <form> <input id="txtValue1"/> <input id="txtValue2"/> <input onclick="AddNumbers();"type="button" value="Add"/> <p>Result:</p> <span id="spanResult"></span> </form>
- 2 回答
- 0 关注
- 520 浏览
添加回答
举报
0/150
提交
取消