• jquery(ajax)+ashx简单开发框架(原创)


    使用ashx作为服务;客户端通过ajax传输数据到ashx服务,直接上代码。

    前端调用(使用jquery1.4.1版本,jquery1.9.1不支持这种写法):

        $.post("Handler/BasicService.ashx", { method: 'Login', 'username': escape($('#txtUserCode').val()), 'password': escape($('#txtPassword').val())) }, function (msg) {
                    if (msg == 'success') {
                        window.location = 'index.aspx';
                    }
                    else {
                        alert(msg);
                    }
                });
    

      

    ashx服务:

     public void ProcessRequest(HttpContext context)
     {
                //不让浏览器缓存
                context.Response.Buffer = true;
                context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
                context.Response.AddHeader("pragma", "no-cache");
                context.Response.AddHeader("cache-control", "");
                context.Response.CacheControl = "no-cache";
                context.Response.ContentType = "text/plain";
             
                Request = context.Request;
                Response = context.Response;
                Session = context.Session;
                Server = context.Server;
                string method = Request["Method"].ToString();//接收提交过来的Method参数
                MethodInfo methodInfo = this.GetType().GetMethod(method);//通过反射获取传递过来的Method(方法名称)类型
                methodInfo.Invoke(this, null);
     }

    具体方法:

       public void Login()
       {
        UserModel user;
        string username = Request["username"].ToString(); //获取请求username参数值
        string password = Request["password"].ToString(); //获取请求password参数值
        //操作业务逻辑。。。
       }
  • 相关阅读:
    hdu2151
    hdu1028
    hdu1398
    hdu1465
    hdu2853
    poj2195
    poj2255
    JS正则校验数字,特殊字符,邮箱基本格式
    JS正则校验数字,特殊字符,邮箱基本格式
    io读取文件内容乱码处理
  • 原文地址:https://www.cnblogs.com/KingLei/p/ashx_ajax.html
Copyright © 2020-2023  润新知