After clicking the submit button, the user submits parameters to the server through Ajax. After the server is added to the database, the user returns the Add result. The page determines based on the results returned by the server. If the ADD is successful, update the content to the page (append () method ).
For users, the entire process is refreshing without interrupting user operations.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "no refreshing comments. aspx. cs" inherits = "ajax _ No refreshing comments" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Server code: insertcomment. ashx
<%@ WebHandler Language="C#" Class="InsertComment" %>using System;using System.Web;public class InsertComment : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; var response = context.Response; var request = context.Request; string name = request["name"]; string content = request["content"]; string time = request["time"]; jiang_Db newdb = new jiang_Db(); try { newdb.ExecSql_None(string.Format("insert into comment([name],[content],[uptime]) values('{0}','{1}','{2}')",name,content,time)); response.Write("success"); } catch (Exception) { response.Write("error"); } } public bool IsReusable { get { return false; } }}