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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.