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