ashx文件的使用实例

前端页面

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax。aspx。cs" Inherits="About_ajax" %>

<!DOCTYPE>

<html>
<head runat="server">    
     <title>Jquery Ajax实例</title>  
       <script type="text/javascript">
        $(document).ready(function() {
            $("#dbtn").click(function() {
                $.ajax({
                    type: "POST",
                    //dataType:"Text",  
                    url: "AjaxHandler。ashx",
                    data: { name: "admin", pass: "admin" },
                    beforeSend: function() { $("#ds").html("loading"); },
                    success: function(msg) { $("#ds").html("<p>" + msg + "</p>"); }
                });
            });
            //
            $("#btn_cbfbh").click(function() {
                //var zbm = '111';
                //alert(zbm);
                $.ajax({
                    type: "POST",
                    //dataType:"Text",  
                    url: "S_CBFBM。ashx",
                    data: { ZBM: "51011200100200" },
                    beforeSend: function() {
                        //$("#div_load").visible = true;
                    },
                    success: function(msg) {
                        //$("#div_load").visible = false;
                        $("#ds").html("<p>" + msg + "</p>");
                        $("#CBFBM").val(msg);
                    }
                });
            });
            //
        });
        function js_function_get_cbfbm(p_zdm) {
            $.ajax({
                type: "POST",
                url: "S_CBFBM。ashx",
                data: { ZBM: p_zdm },
                beforeSend: function() {
                    //$("#div_load").visible = "true;
                },
                success: function(msg) {
                    //$("#div_load").visible = false;
                    $("#ds").html("<p>" + msg + "</p>");
                    $("#CBFBM").val(msg);
                }
            });
        };
    </script>
</head>
<body οnlοad="javascript:{js_function_get_cbfbm('sfsfds');}">
    <form id="form1" runat="server">
    <div>
      <div id="ds"><p>我是AJAX原来的文字!</p></div>  
      <input type="button" value="提交AJAX测试" id="dbtn" name="dbtn" />  
      <br />
      <input type="text"  id="CBFBM" name="CBFBM"/>   
      <input type="button" value="获取成包方编号" id="btn_cbfbh" name="btn_cbfbh" /> 
      <br />
      <div id="div_load" ><p></p></div>     
    </div> 
    <script type="text/javascript">
          var zbm='';
          if(zbm=='') zbm='51011200100900';
          //js_function_get_cbfbm(zbm);
    </script> 
    </form>
</body>
</html>

 

ashx文件使用代码

<%@ WebHandler Language="C#" Class="AjaxHandler" %>

using System;
using System.Web;

public class AjaxHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        //context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        context.Response.ContentType = "text/plain";

        //context.Response.Write("Hello World");  
        if (context.Request["name"].ToString() == "admin" &&
            context.Request["pass"].ToString() == "admin")
        {
            context.Response.Write("Y");
        }
        else
        {
            context.Response.Write("N");
        } 
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

    [System.Web.Services.WebMethod]
    public static string SayHello()
    {
        return "Hello Ajax! AjaxHandler。ashx";
    } 

}


 

<%@ WebHandler Language="C#" Class="S_CBFBM" %>

using System;
using System.Web;

/** <summary>
/// 功能:获取 编号
/// </summary>
public class S_CBFBM : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) 
    {        
        context.Response.ContentType = "text/plain";
                  
        string zbm=context.Request["ZBM"].ToString();
        zbm=zbm.Trim();
        if(zbm!="") 
        {
            string cbfbm = zbm + "001";
            context.Response.Write(cbfbm);
        }
        else
        {
            context.Response.Write("");
        } 
    }
 
    public bool IsReusable 
    {
        get 
        {
            return false;
        }
    }

    [System.Web.Services.WebMethod]
    public static string SayHello()
    {
        return "Hello Ajax! S_CBFBM。ashx";
    } 

}


 

 

文章转载自:     ashx 文件怎么用     http://www.studyofnet.com/news/286.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值