Add comments without refreshing Ajax (jquery Version)

Source: Internet
Author: User

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;        }    }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.