This is my spring controller
@RequestMapping(value = "/app/{appId}/save.html",method=RequestMethod.POST)
public @ResponseBody String myFunction
(@PathVariable("appId") String id, @RequestBody Map<String, String> data1) {
return "hello";
}
This is my ajax request
$.ajax({
type : 'POST',
url : '/app/${param.appID}/save.html',
data : JSON.stringify(myJsonData),
dataType : "json",
success : function(data, textStatus,
xhr) {
var response = xhr.responseText;
if (response !== "hello") {
alert('sad');
} else {
alert('happy');
}
}
});
The problem is , this request never reaches the controller and gets stuck . If I remove data and data1, things work fine. Can some help me with what am I doing wrong.
Update: Here's the error as shown by firebug
415 Unsupported Media Type : The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ()
Here is my json object
myJsonData= {
"data1" : $("input[name=key1]:checked").val(),
"data2" : $("input[name=key2]:checked").val(),
"data3" : $("input[name=key3]:checked").val()
};