//var obj = $("#J_Form").serialize(); $("#btnSubmit").click(function(){ var prodName = $("#J_Form").find("select[name='prodName']").val(); var subProdName = $("#J_Form").find("select[name='subProdName']").val(); var div1Arr = new Array(); var obj = new Object(); $('.div1').each(function(){ //循环div1 var div1=$(this); var feeType1Var = div1.find("select[name='feeType1']").val(); div1.find('.subDiv1').each(function(){ //循环subDiv1 var subDiv1=$(this); var obj = new Object(); obj.feeType = feeType1Var; obj.repayWay = 0; obj.fundName = subDiv1.find("select[name='fundName']").val(); obj.dest = subDiv1.find("select[name='dest']").val(); obj.transType = subDiv1.find("select[name='transType']").val(); div1Arr.push(JSON.stringify(obj)); }); }) $.ajax({ type : 'POST', traditional:true,//防止深度序列化 cache:false, async:false, dataType : 'json', url : '/fundAcct/menu/addFundConfigToDB', data : { "prodName" : prodName, "subProdName" : subProdName, "dataArr" :div1Arr }, success : function(data) { if (data.msg=='success') { BUI.Message.Alert("success", "success"); // 刷新页面 } else { BUI.Message.Alert("error:系统异常", "error"); } }, error : function(data) { BUI.Message.Alert("error:系统异常", "error"); } }); });
后台Controller部分:
@RequestMapping("/addFundConfigToDB") @ResponseBody public JSONObject modifyTransCodeToDB(HttpServletRequest request, Map<String, Object> model) { //log.info("交易类型--------------------修改落库DB"); JSONObject json = new JSONObject(); Map<String, String[]> webParaMap = request.getParameterMap(); String dataArry[] = webParaMap.get("dataArr");// TODO parse to Object String prodName = webParaMap.get("prodName")[0]; String subProdName = webParaMap.get("subProdName")[0]; String userName = null; if (null != SsoSession.getCurrentUser(request)) { userName = SsoSession.getCurrentUser(request).getName(); } //log.info("修改交易类型,id = {},名称 = {},当前用户 ={}", id, transName, userName); if (dataArry.length > 1) { json.put("msg", "success"); return json; } else { json.put("msg", "fail"); return json; } }
总结
以上所述是小编给大家介绍的jQuery实现表单动态加减、ajax表单提交功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章: