jquery调用一般处理程序的多个方法
jquery调取方式: <script type="text/javascript"> $(function () { $.get("/Ashx/GetTraceabilityJson.ashx?" + new Date(), { 'ProductCode': '<%=ProductCode %>', 'BatchNumber': '<%=BatchNumber %>', 'command': 'GetFlowGraph' }, function (data) { if (data != null) { var data = $.parseJSON(decodeURIComponent(data)); var nodes = eval(data[0].value); var links = eval(data[1].value); if (nodes.length > 0) { setNodes(nodes); setLinks(links); } } }); }); </script>
一般处理程序后台编写方法;
/// <summary> /// GetTraceabilityJson 的摘要说明 /// </summary> public class GetTraceabilityJson : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request["command"] != null) { string command = context.Request["command"]; System.Reflection.MethodInfo method = GetType().GetMethod(command); if (method != null) { method.Invoke(this, new object[] { context }); } } } public bool IsReusable { get { return false; } } public void GetFlowGraph(HttpContext context) { string ProductCode = ParameterFilter.GetString(context.Request.QueryString["ProductCode"]); string BatchNumber = ParameterFilter.GetString(context.Request.QueryString["BatchNumber"]); if (string.IsNullOrEmpty(BatchNumber)) { return; } //string a = "[{\"name\":\"node\",\"value\":\"[{'id': '0','name': '生产入库单:SC20131217000116', 'statue': 'Oval'},{'id': '1','name': '销售出库单:XS20131217000116', 'statue': 'Normal'},{'id': '5','name': '销售出库单:XS20131217000116', 'statue': 'Normal'},{'id': '6','name': '销售出库单:XS20131217000116', 'statue': 'Normal'},{'id': '7','name': '销售出库单:XS20131217000116', 'statue': 'Normal'},{'id': '2','name': '销售出库单:XS20131218000120', 'statue': 'Normal'},{'id': '3','name': '采购入库单:CG20131218000025', 'statue': 'Normal'},{'id': '4','name': '销售出库单:XS20131218000121', 'statue': 'Normal'}]\"},{\"name\":\"link\",\"value\":\"[{'name': '','target': '1','source': '0'},{'name': '','target': '2','source': '0'},{'name': '','target': '3','source': '2'},{'name': '','target': '4','source': '3'},{'name': '','target': '5','source': '0'},{'name': '','target': '6','source': '0'},{'name': '','target': '7','source': '0'}]\"}]"; JavaScriptSerializer jss = new JavaScriptSerializer(); Node[] values = new Node[] { new Node() { name = "node", value = ("[" + sbNodes.ToString().TrimEnd(',') + "]") }, new Node() { name = "link", value = ("[" + sbNodeLinks.ToString().TrimEnd(',') + "]") } }; context.Response.ContentType = "text/plain"; string json = jss.Serialize(values); context.Response.Write(json); context.Response.End(); }