MVC2 uses jquery. Ajax to send and display data

Source: Internet
Author: User

The effect is as follows:

Click Submit to insert the data in the text box to the database.

Page SectionCode:

 

Jquery code:

$ ( Function  () {$ ( "# Sendmsg"). Click ( Function  () {// Triggered $. Ajax ({type: "Post" , URL: "/MSG/sendmicromsg /" , // Send to sendmicromsg action in msgcontroller. Datatype: "JSON" , Data :{ "Content": $ ("# contents"). Val ()}, // Insert the text in the "contents" ID to the database success:  Function  (Data) {// returned data. Alert (data );  }, Error:  Function  (Error) {alert ( "Error" );  }});  Return   False  ;});}); 

The following describes how to obtain parameters for the Controller:

  // /<Summary>          //  /Send Weibo messages          //  /</Summary>  Public actionresult sendmicromsg (formcollection frmcollection) {isession _ Session = SM. getsession (); string content = Frmcollection ["content" ]. Tostring (); // obtain the parameters passed by Ajax. You don't need to worry about other code. Now you know that the parameter is obtained. Write your inserted data. Trule = New  Trule (_ session); trule. Post (content, userrule. getcurrentuserid ()); Return  JSON (content); // here I can also return an object, or a piece of spliced HTML code: returned object: joson (New trule {id = 4, name = ""});} 

Is the effect of clicking submit:

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.