伪“MVC”,一般处理程序的使用

前台js:

$.ajax({
                type: "GET",
                url: "test.ashx",
                data: { username: "张三", method: "test" },
                //dataType: "json",
                success: function (data) {
                    var data1 = eval('(' + data + ')');
                    alert(data1.uname);
                }
            })

后台:

using System;
using System.Collections.Generic;
using System.Web;

namespace WebApplication1
{
    /// <summary>
    /// test 的摘要说明
    /// </summary>
    public class test : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string methodType = context.Request.Params["method"];
            switch (methodType)
            {
                case "test":
                    PTest(context);
                    break;
            }
        }

        public void PTest(HttpContext context)
        {
            string userName = context.Request.Params["username"];
            context.Response.Write(userName);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

  

posted @ 2016-09-05 11:56  blackday  阅读(222)  评论(0)    收藏  举报