I’m sending a POST request with json like this:
$.ajax({
type: "POST",
url: "myurl.htm",
contentType: "application/json",
data: '{"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}',
dataType: "json"
});
When I look at this requet from Network its passing the following payload
{"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}
However, I want the request load to be:
mydata: {"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}
Because my controller is accepting the following:
@RequestMapping(headers ={"Accept=application/json"},value="/myurl.htm", method= RequestMethod.POST)
public ModelAndView mymethod(
@RequestParam(value="mydata", required=false) String mydata {
logger.info(mydata);
}
So I need a way to simply give a parameter name to the json data I’m sending to the server as POST request.
what about this? Since json is just a string and you are posting data this should work.