Spring MVC $.ajax does not specify ContentType, causing the background to not receive data

Source: Internet
Author: User

var formData = json.stringify (this.rows);  Convert data from a form to a string
$.ajax ({type:"Post", URL:'Http://localhost:8080/data', Data:formdata, DataType:"JSON", contentType:  "application/json;charset=utf-8"  , success:function (data) {}}); began to miss the Red property settings, resulting in the background is always unable to parse the data, can receive data, but very messy characters. 

$.ajax http://www.runoob.com/jquery/ajax-ajax.html has many properties to set

@RequestMapping (value ="/data", method =requestmethod.post) Public voidgetData (@RequestBody String str) throws ioexception{Org.codehaus.jackson.map.ObjectMapper mapper=NewOrg.codehaus.jackson.map.ObjectMapper (); Javatype Javatype= Mapper.gettypefactory (). Constructparametrictype (ArrayList.class, Testmodel.class); List<TestModel> list = (list<testmodel>) Mapper.readvalue (str, javatype); System. out. println (str); System. out. println (list); }

There is one more question unresolved:

    " /data ", method = requestmethod.post)    publicvoid getData (@RequestBody list< Testmodel> list)

Unable to receive data to list

Spring MVC $.ajax does not specify ContentType, causing the background to not receive data

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.