简单的Ajax异步提交

<!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;
            }
        }
    }
}

 

转载于:https://www.cnblogs.com/bjxingch/articles/5716827.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值