我有一个包含隐藏输入的html表单。我想用json字符串(可能是长字符串)填充此输入,然后通过我的控制器中的@RequestParam
获取它。这是我的javascript代码(注意表单是由页面上的某个事件生成的):
var filters = JSON.stringify("some data");
//I used console.log for print out the filters and this is ok.
$("body").append('<form target="_blank" id="excel" action="/company/excel" method="POST"></form>');
$('<input type="hidden" name="filter" value="'+filters+'" />').appendTo("#excel");
$("#excel").submit();
这是我的行动:
@RequestMapping(value = "company/excel", method = RequestMethod.POST)
public void companyExcelExport(@RequestParam String filter) throws IOException{
System.out.println(filter);
}
执行操作时,只在netbeans控制台中打印“{”。有什么问题?
我使用了console.log(filters)
并且它返回了我:
{"search":false,"nd":1421663503100,"rows":10,"page":1,"sidx":"","sord":"asc","pageGridColModelList":[{"name":"id","index":"id","width":150,"sortType":"integer","hidden":true,"hiddenlg":true,"stype":"text","searchoptions":{"stype":"integer","sopt":["eq","ne","lt","le","gt","ge","bw","bn","in","ni","ew","en","cn","nc"]}},{"name":"name","index":"name","width":250,"sortType":"string","hidden":false,"hiddenlg":false,"stype":"text","searchoptions":{"stype":"text","sopt":["eq","ne","lt","le","gt","ge","bw","bn","in","ni","ew","en","cn","nc"]}},{"name":"createAt","index":"createAt","width":420,"sortType":"date","hidden":false,"hiddenlg":false,"stype":"text","searchoptions":{"stype":"integer","sopt":["eq","ne","lt","le","gt","ge","bw","bn","in","ni","ew","en","cn","nc"]}}]}
答案 0 :(得分:0)
我改变了:
$('<input type="hidden" name="filter" value="'+filters+'" />').appendTo("#excel");
成:
$('<input type="hidden" name="filter" id="filter" />').appendTo("#excel");
$("#filter").val(filters);
现在这很有效。