标签:style blog http color java os io 文件
前台代码:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JS直接调用C#方法</title> <script type="text/javascript" src="/Scripts/Jquery-1.9.1.js"></script> <script type="text/javascript"> $(function () { $("#btnCall").click(function () { $.post("/apps/demo1/filters/OperateHandler.ashx?test=12399", { Id: 1, Name: "test" }, function (data) { }, "text"); }); }); </script> </head> <body> <input type="button" id="btnCall" value="Call" /> </body> </html>
?后面的参数可以用context.Request.QueryString来访问,json对象里的参数【{Id:1,Name:"test"}】可以用context.Request.Form来访问
创建一个ashx文件,ashx文件代码如下【内容为默认创建内容,未作修改】:
public class OperateHandlerashx : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); } public bool IsReusable { get { return false; } } }
标签:style blog http color java os io 文件
原文地址:http://www.cnblogs.com/kelei12399/p/3892121.html