我正在用json发送一个POST请求:
$.ajax({
type: "POST",
url: "myurl.htm",
contentType: "application/json",
data: '{"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}',
dataType: "json"
});
当我从Network
查看此requet时,它传递了以下有效载荷
{"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}
但是,我希望请求加载为:
mydata: {"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}
因为我的控制器正在接受以下内容:
@RequestMapping(headers ={"Accept=application/json"},value="/myurl.htm", method= RequestMethod.POST)
public ModelAndView mymethod(
@RequestParam(value="mydata", required=false) String mydata {
logger.info(mydata);
}
所以我需要一种方法来简单地给我作为POST请求发送到服务器的json数据一个参数名称。
答案 0 :(得分:0)
$.ajax({
type: "POST",
url: "myurl.htm",
contentType: "application/json",
data: 'mydata={"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}',
dataType: "text"
});