• 一般处理程序的使用


    在AJAX的地址中 

    $.ajax({
    type: "post",
    url: "../../ajax/xxxHandler.ashx?action=save",

    cache:false//强迫当前请求必须访问后台,不能使用客户端的缓存

    data: { "v": fid, "v1": sl },
    success: function (result) {
                      alert(result);
                    }
          })

    右击项目吗,添加一般处理程序:

      

    
    

    public class fixturesHandler : IHttpHandler
    {

      public void ProcessRequest(HttpContext context)

            {
                context.Response.ContentType = "text/plain";
                string strAction = context.Request.QueryString["action"];
                switch (strAction)
                { 
                    case "save":
                        save(context);
                        break;
                    //case "login":
                    //    Login(context);
                    //    break;
                }
           context.Response.End(); }

     private void save(HttpContext context)
        {
            string sqlstring = System.Configuration.ConfigurationManager.AppSettings["LocalConnectionString"];
            string fid = context.Request["v"];
            string sl = context.Request["v1"];
            SQLHelper s = new SQLHelper(sqlstring);
            string sql = @"xxx";
            bool result = s.Execute(sql);
            if (result == true)
                context.Response.Write("保存成功!");
            else
            {
                string UpdateSql = @"xxx";
                if (s.Execute(UpdateSql) == true)
                    context.Response.Write("修改成功!");//最终,返回给前台的result的字符串
                else
                {
                    context.Response.Write("保存失败!");
                }
            }
    
        }

    //最后这一段不能丢,丢了你的一般处理程序就运行不起来了。
     public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
    

    }//这个是类的结束符!!!

     
    
    
    
     

     属性IsReusable是IHttpHandler要求实现的一个属性,将其设置为false的目的是:该类的一个实例不能用来处理多个请求。

  • 相关阅读:
    剑指offer-02-替换空格
    剑指offer-03-从尾到头打印链表
    剑指offer-01-二维数组中的查找
    JS-几类函数
    【工具使用】—VSCode
    【工具使用】—Chrome工具使用技巧
    【codeReview】button-disabled
    c语言中结构体位段
    结构体位断
    malloc/free与 new/delete的区别
  • 原文地址:https://www.cnblogs.com/vichin/p/6069603.html
Copyright © 2020-2023  润新知