Transfer JSON data through Ajax and spring background

Source: Internet
Author: User

The 415 (Unsupported media type) error is always returned when data is passed from the page to the background via Ajax, and the data is not available in the background. As shown in the following:

In trying to solve this problem, we first have to understand the concept:

    1. @requestmapping @ requestbody and @responsebody usage, this has a lot of blogs to refer to.
    2. The difference between a JSON object and a JSON string.
      Person ={"name": "Nadech"}//This is a JSON object
      person= "{" name ":" Nadec "}"//This is a JSON string
      Both can be converted by json.parse () and json.stringify ().
@requestbody the process of transmitting JSON data (JSON strings) back to the platform by Ajax

, first we want to guarantee the transmission of the Content-type:application/json charst= "Utf-8
The second arrow in the transmitted JSON string indicates the form, not a pile of letters.
By specifying Content-type in Ajax and Json.stringify () to data, you can then check the header to see if it is correct.

Second, there is no above error, consider the version compatibility issue of Jackson and spring MVC and the configuration of SPRINGMVC.

Which, in terms of configuration, such as

Note that the code of the red arrow indicates that the code is usually directly behind the scan controller package. The meaning of a literal understanding is the annotation drive of MVC.

Summarize:

You need to consider the JSON format for the transfer and Jackson's version and configuration issues.

Transfer JSON data through Ajax and spring background

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.