jquery submits the form via Ajax and returns the results _jquery

Source: Internet
Author: User
As follows:

1: Non-Ajax

Front desk:

Corresponding background:

Ajax of 2:jquery

Before introducing the use of jquery to submit a form, we need to first refer to Jquery.form.js, which comes from http://www.malsup.com/jquery/form/, so we need to refer to the JS file:

Functional Requirements: Ajax submits the form, handles the request in the controller Helloworld4controller, and returns a number of data formatted as JSON.

First, we assume that the returned JSON entity is:

Copy Code code as follows:

public class Loginresultdto
{
public bool Success {get; set;}
public string Message {get; set;}
public string ReturnUrl {get; set;}
}

The code for the Controller section is:
Copy Code code as follows:

public class Helloworld4controller:controller
{
Public ActionResult Index ()
{
if (Request.isajaxrequest ())
{
String str1 = request.form["Text33"];
String str2 = request.form["Text44"];
Return Json (new MvcApplication5.Controllers.HelloWorld3Controller.LoginResultDTO {Success = true, message = str1 + str2, ReturnUrl = "Someurl"});
}
Else
{
return View ();
}
}
}

The code above tells us that it is also convenient if we want to return to another entity.

Front Section code:

If the button does not use submit, the image above is changed to the following form:


SOURCE Download: Mvcapplication5.zip

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.