zoukankan      html  css  js  c++  java
  • 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参数值
        //操作业务逻辑。。。
       }
  • 相关阅读:
    使用命令xrandr设置当前系统的显示分辨率及显示的旋转脚本
    CODEFORCE 246 Div.2 B题
    Android数据的四种存储方式之SQLite数据库
    C语言默认參数值的实现
    Android开发环境搭建
    也谈OpenFlow, SDN, NFV
    解决设置redmineblacklog的按钮无效问题
    长方体的研究
    表面张力与浮力
    表面张力与浮力
  • 原文地址:https://www.cnblogs.com/KingLei/p/ashx_ajax.html
Copyright © 2011-2022 走看看