Spring MVC Ajax Submission Method

Source: Internet
Author: User

Using jquery's AJAX approach to submitting

The first, submitted as a JSON object

var jsondata = {"Name": "Zhangsan", "Sex": "Boy"};$.ajax ({type: "POST", url: "Test_post1", data:jsondata,//success:f Unction (data) {alert (data);}});

If the data returned by the request is in JSON format, then there are attributes: DataType: ' JSON '

@RequestMapping (value = "/test_post1", method = Requestmethod.post) @ResponseBodypublic resultdto test_post1 ( HttpServletRequest request, User user) {resultdto result = new Resultdto (); return result;}

Using @responsebody, the JSON string returned in response is the corresponding format.

The second, submitted as a JSON string

var jsondata = {"Name": "Zhangsan", "Sex": "Boy"};$.ajax ({type: "POST", url: "Test_post2", Data:JSON.stringify (Jsondata ), ContentType: ' Application/json ', success:function (data) {alert (data);}});

@RequestMapping (value = "/test_post2", method = Requestmethod.post) @ResponseBodypublic resultdto test_post2 ( HttpServletRequest request, @RequestBody Jsonobject jsonobject) {resultdto result = new Resultdto (); return result;

Using jquery's post to submit

var jsondata = {"Name": "Zhangsan", "Sex": "Boy"};$.post ("Test_post3", Jsondata, function (data) {alert (data);});

@RequestMapping (value = "/test_post3", method = Requestmethod.post) @ResponseBodypublic resultdto test_post3 ( HttpServletRequest request, User user) {resultdto result = new Resultdto (); return result;}

Note:

If the data returned by the request is in JSON format, use the following notation to request the data:

$.post ("Test_post3", Jsondata, function (data) {alert (data);}, ' json ');

Spring MVC Ajax Submission Method

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.