ASP.NET 中发送请求的页面代码如下:
<head runat="server"> <title></title> <script src="js/jquery-2.1.1.min.js"></script> <script type="text/javascript"> function full() { $.ajax({ type: "post", url: "Handler1.ashx?fun=full", traditional: true, data:{name:"张阿三"}, success:function(data) { alert(data); }, error: function (data) { alert(data); } }); } </script> </head> <body> <form id="form1" runat="server"> <div> <button onclick="full()">点击触发</button> </div> </form> </body>
一般处理程序的代码如下:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string fun = context.Request["fun"]; string result = ""; if (fun=="full") { result = "Hello " + context.Request["name"]; } context.Response.Write(result); context.Response.End(); }
注意:一般处理程序的返回值是用
context.Response.Write(result);
context.Response.End();
这个组合返回的!