方法 $.post(url,params,function(data){});
表单的action,method属性都没有
button的type不能为submit只能为button
前台代码
<script type="text/javascript"> $(function() { //异步提交表单 $("#save").click(function(){ $.post("${ctx}/order/save.action",$("#form1").serialize(),function(data){ if(data=="true") { alert ("备注保存成功"); } }) }) }) </script> <form id="form1" > <input type="hidden" name ="oid" value="${orderVo.id}"> <textarea class="form-control" name ="remark" id ="text" rows="3" cols="140" >${orderVo.remark}</textarea> <input id="save" class="btn btn-primary" type="button" value="保存" />
后台代码:
public void save(){ PrintWriter out=null; try { System.out.println(oid); System.out.println(remark); orderService.saveRemark(oid,remark); HttpServletResponse response=ServletActionContext.getResponse(); out=response.getWriter(); out.print(true); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); out.flush(); out.close(); out.println(0); } }
参考文章:
http://1194867672-qq-com.iteye.com/blog/1945827
时间: 2024-11-08 10:09:40