<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ajax异步提交</title>
<meta charset="utf-8"/>
<script src="scripts/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(function() {
$("#btnCal").click(function() {
$.post("BLL/Ajax01.ashx", { "num1": $("#txtNum1").val(), "num2": $("#txtNum2").val() },
function(data,status) {
if (status == "success") {
$("#res").val(data);
} else {
alert("计算错误~!");
}
});
});
});
</script>
</head>
<body>
<input type="text" name="txtNum1" id="txtNum1"/>+
<input type="text" name="txtNum2" id="txtNum2"/>=
<input type="text" name="res" id="res"/>
<input type="button" id="btnCal" value="计算"/>
</body>
</html>
********************一般处理程序********************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace DemoHTML.BLL
{
/// <summary>
/// Ajax01 的摘要说明
/// </summary>
public class Ajax01 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//获取参数
int num1 = Convert.ToInt32(context.Request.Params["num1"]);
int num2 = Convert.ToInt32(context.Request.Params["num2"]);
int res = num1 + num2;
context.Response.Write(res.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}