Ajax back to the table JSON format datagram 415 error

Source: Internet
Author: User

Problem Description:

Ajax back platform JSON format datagram 415 error, as shown in

Page code

function Saveuser () {var uuid = document.getElementById ("uuid"). Value;var Idcard = document.getElementById ("Idcard"). Value;alert (uuid+idcard);//var result = new Object ();//result.uuid = Uuid;//result.idcard = Idcard;//var SaveData = JSON. Stringify (result);//alert (SaveData); $.ajax ({url: "xdds/saveuser.do?random=" + math.random (), type: "POST", Data: {" UUID ": UUID," Idcard ": Idcard},//data:savedata,datatype: ' JSON ',//contenttype: ' Application/json ', success:function ( Data) {}});

Background code

@RequestMapping (value = "/saveuser.do", method = {requestmethod.post})    @ResponseBody    public   map<string, object> saveuser (@RequestBody mapuser user) {        Mapnew hashmap< String, object>();        System.out.println (User.getuuid ()+User.getidcard ());        Map.put ("result", "FDA");         return map;            }

Error Analysis: 415 (Unsupported media type) The requested format is not supported by the requested page

The correct JSON format {key:value, Key:value}key, and value should all be enclosed in double quotes. The data in the foreground code in the above value does not have double quotation marks, so it causes an error (because the item in front of the contact is no problem)

So preliminary analysis may be a problem for the framework, and some frameworks can

Data: {"UUID": UUID, "Idcard": Idcard} This package is in the correct JSON format

。 Specific reasons still do not know, Bo Master is also small white, and other bloggers to figure out what will be shared

Workaround: Open the code for the foreground comment

var saveData = json.stringify (Result)
This function can be converted into a true JSON format.

PS: Small white One, there is no place to ask the great God, God knows the specific reason, please specify, not very grateful

Ajax back to the table JSON format datagram 415 error

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.