Ajax(二) 调用Handler.ashx后台进行异步传递

ashs


<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/json";
      //  context.Response.Write("{\"msg\":\"Hello World" + context.Request["name"] + "来自handler.ashx\"}");
        context.Response.Write("{\"msg\":\"Hello World" + context.Request["name"] + "来自handler.ashx\"}");


        context.Response.End(); 
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
} 

前台

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ajax传递_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     <script type="text/javascript" src="../../Scripts/jquery-3.4.1.js"></script>
 <script type="text/javascript" src="../Scripts/jquery-3.4.1.js"></script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        
        <input  type ="button" id ="b1"  value="按钮b1"  />
        
        <input  type ="button" id ="c1"  value="按钮c1"  />


        <input type ="text" id ="Text1" value="张三">  


        <input name="funItem" value="1" type="checkbox" id="ck1" />c#
   <input name="funItem" value="2" type="checkbox" />html
   <input name="funItem" value="3" type="checkbox" />javascript


    </div>
    </form>
</body>
</html>

<script>


    $( "#b1" ).bind( "click", function ()
    {
        $.ajax( {
            type: "post",
            url: "Handler.ashx",
            data: "name=" + $( "#Text1" ).val(),
            success: function ( result )
            {
                alert( result.msg );
            }
        } );
    } );


</script>

<script type="text/javascript">

    $( "#c1" ).bind( "click", function ()
    {
        $.ajax( {
            type: "post",
            url: "Handler.ashx",
            data: "name=" + $( "#ck1" ).val(),
            success: function ( result )
            {
                alert( result.msg );
            }
        } );
    } );



</script>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值