Objective:
This example probably features the front desk to invoke the generic handler (Handler) through jquery Ajax, get the information that the form needs to display, and then convert it back to the foreground in JSON format, and the front desk gets the data to loop through the table, preferably with the row attached to the sheet.
Goal:
A familiarity with the use of simple jquery Ajax
b Learn how to construct basic JSON-formatted data (you can also build JSON through a third-party DLL)
C familiar with the basic usage of handler
1 Simple Effect Chart
2 Front Code
<%@ Page language= "C #" autoeventwireup= "true" codefile= "DialogAjax.aspx.cs" inherits= "Jquerytest_dialogajax"% > <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
3 Handler code
<%@ WebHandler language= "C #" class= "Testhandler"%> using System;
Using System.Web;
Using System.Collections.Generic;
Using System.Text;
Using Datadal;
Using Dataenity;
public class Testhandler:ihttphandler {HttpRequest Request;
HttpResponse Response; The public void ProcessRequest (HttpContext context) {//does not allow the browser to cache the 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; String method = Request[' method '].
ToString (); System.Reflection.MethodInfo MethodInfo = this. GetType ().
GetMethod (method);
Methodinfo.invoke (this, null);
public void GetModuleInfo () {StringBuilder sb = new StringBuilder (); String jsondata = String.
Empty; List<module> lsmodule = Moduledal.getmodulelist (); Sb.
Append ("{\" module\ ": ["); for (int i = 0; i < Lsmodule.count i++) {jsondata = "{\ modulenum\": "+" \ "" + lsmodule[i]. Modulenum + "\" "+", \ "modulename\": "+" \ "" + lsmodule[i]. ModuleName + "\" "+", \ "moduledes\": "+" \ "" + lsmodule[i].
Moduledes + "\" "+"}, "; Sb.
Append (Jsondata); if (Lsmodule.count > 0) sb = sb. Remove (sb.)
Length-1, 1); Sb.
Append ("]}");
Response.Write (SB);
public bool IsReusable {get {return false; }
}
}
The above code is very simple, JQuery Ajax dynamically generated table table content is complete, I hope to help.