jquery(ajax)+ashx简单开发框架(原创)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                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參數值//操作業務邏輯。。。}?
轉載于:https://www.cnblogs.com/KingLei/archive/2013/04/18/ashx_ajax.html
總結
以上是生活随笔為你收集整理的jquery(ajax)+ashx简单开发框架(原创)的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: svn钩子程序上传文件中文文件导致报错的
 - 下一篇: (转)Apache Ant 环境开发An