Asynchronous request in Json format (submit comments)

Source: Internet
Author: User

Asynchronous request in Json format (submit comments)

Paste the code and read the code to understand the relevant logic.

Html code:

Existing comments:
Js Code:
$ ("# Send "). click (function () {$. get ("doSave. ashx ", {// call the json plug-in u_name: $ (" # username1 "). val (), // json data/value pairs u_cont: $ ("# content "). val ()}, function (data) var uName = data. username; // Note: username and doSave here. dic in ashx. var uCont = data. content; var txtHtml = "" + uName + ":

"+ UCont +"

"$ (" # ResText ").html (txtHtml); // Add the returned data to the page}," json ");})
Plug-in code:
<% @ WebHandler Language = "C #" Class = "doSave" %> using System; using System. web; public class doSave: IHttpHandler {public void ProcessRequest (HttpContext context) {var dic = new System. collections. generic. dictionary
 
  
(); // String jsonStr = "{}"; // create a new string jsonStr context. response. contentType = "text/json"; // defines the returned content type as json string uname = context. request. queryString [0]; // obtain the first parameter in the request parameter. You can also directly use uname string commet = context. request. queryString [1]; // defines the string uname and commet as the string context to be queried in the context request. request. params ["username"]; QyertStrubg: query string dic. add ("username", uname); // Add the string to the object dic. add ("content", commet); jsonStr = Newtonsoft. json. jsonConvert. serializeObject (dic); // the serialization set is a json string context. response. write (jsonStr);} public bool IsReusable {get {return false ;}}}
 

The effect is as follows: Enter the relevant text in the input box and click Submit. The text written is displayed automatically below, so you do not need to jump to other pages.

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.