Im trying to post Json data using Dojo post i.e dojo.xhrPost() method. I found many solutions in stacks which have not solved my issue. Am passing the json data with content -type 'application/json'.Please find below code snippet of Client (JS) and Server (Spring MVC Controller).
I have added following jar in my Lib folder for JSON conversion
1.jackson-core-asl-1.9.10.jar
2.jackson-mapper-asl-1.9.10.jar
3.jackson-jaxrs-1.9.13.jar
Point:Json data is passing is proper format. JSP is my view Resolver.
var map = dojo.toJson({id:'1',name:'er'})
var xhrArgs = {
url : _context+'/exchangeRate/save-exchange',
postData : map,
handleAs: "json",
headers : {
'Content-Type' : 'application/json,charset=utf-8',
},
load : function(response) {
console.log(response);
},
error : function(error_msg, details) {
alert(error_msg);
console.log(details)
}
}
dojo.xhrPost(xhrArgs);
Below is my Spring Controller Method
@RequestMapping(value = "/exchangeRate/save-exchange", method =
RequestMethod.POST,headers= { "content-type=application/json" },consumes
="application/json",produces = "application/json")
public @ResponseBody
Map saveExchangeRate(@RequestBody Map map) {
return new Hashmap();
}