I. Front-end page:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">Two. ASHX Code:public class Handler1:ihttphandler, irequiressessionstate {HttpRequest Request; HttpResponse Response; public void ProcessRequest (HttpContext context) {Request = context. Request; Response = context. Response; String method = Request["Method"]. ToString ();//url parameter corresponding to Ajax method MethodInfo MethodInfo = this. GetType (). GetMethod (method);//Methodinfo.invoke (this, null); public void Getlzr () {String name = request["Name"]. ToString (); String age = request["Age"]. ToString (); string sex = request["Sex"]. ToString (); int i = Sqlhelper.executenonquery ("Insert into Lzr_name (name,age,sex) VALUES (@name, @age, @sex)", New SqlParameter ("@ Name ", name), New SqlParameter (" @age ", age), New SqlParameter (" @sex ", Sex)); if (i > 0) {//Return Data Response.Write ("T"); } else {Response.Write ("F"); }} public bool IsReusable {get {return false; } } }
Three. Display: Before clicking the button:
After clicking the button:
Ajax, Html, ASP call database