【发布时间】:2012-12-07 02:41:11
【问题描述】:
我是 Spring MVC 的新手。 我有这样的表格,
<form:form action="/myaction.htm" method="post" modelAttribute="myForm" id="formid"> 和一个返回 json 的控制器
public @ResponseBody ResultObject doPost(@ModelAttribute("myForm") MyForm myForm){
System.out.println("myform.input");
}
我可以使用$("#formid").submit(); 提交此内容,并且我的 modelAttribute 工作正常,从 UI 中获取值。
我的问题是,如何以 jquery ajax 方式提交此表单? 我试过了,
$.ajax({
type:"post",
url:"/myaction.htm",
async: false,
dataType: "json",
success: function(){
alert("success");
}
});
表单已提交,但modelAttribute值为null,如何在提交时包含modelAttribute对象(表单正在使用的对象)?
【问题讨论】: