ajax与action的动态交互

xiaoxiao2021-02-28  94

js:

 var datas = $('#frmAdd').serialize();            $.ajax({ type:"POST", dataType:"text", //text支持中文,json乱码 contentType: "application/x-www-form-urlencoded; charset=utf-8", url:"./PlanTaskAction.do?doType=51", data: encodeURI(datas),  //编码 cache: false, async: true, success:function(data){ if(data=="ok"){ alert("保存成功"); document.getElementById('saveplantask').style.display="none"; // parent.location.reload(); } else{ alert("保存失败");  } }, error:function(e){ alert("保存失败");  } });

action:PlanTaskAction.java

try{             PlanTask PlanTask = new PlanTask(); PlanTask.setId(URLDecoder.decode(planTaskForm.getId())); PlanTask.setAnnualplanid(planId); PlanTask.setPlantaskcreationdate(df.format(new Date())); PlanTask.setPlantaskcreator(user.getName()); //用户名 if(planTaskForm.getIsaudited()){ PlanTask.setAuditflag("1");  //重点项目 }else{ PlanTask.setAuditflag("2");  //非重点项目 } PlanTask.setPlantaskstate("草稿"); PlanTask.setPlantasktype(URLDecoder.decode(planTaskForm.getPlantasktype(),"utf-8")); //解码 PlanTask.setTaskexecstate("未完成"); PlanTask.setTaskname(URLDecoder.decode(planTaskForm.getTaskname(),"utf-8")); PlanTask.setTaskobjective("上报"); PlanTask.setIsaudited(planTaskForm.getIsaudited()); PlanTask.setTaskstarttime(URLDecoder.decode(planTaskForm.getTaskstarttime())); if(!planTaskForm.getTaskfinishtime().equals("")){ if(URLDecoder.decode(planTaskForm.getTaskfinishtime()).length()>11){ PlanTask.setTaskfinishtime(URLDecoder.decode(planTaskForm.getTaskfinishtime())); }else{ PlanTask.setTaskfinishtime(URLDecoder.decode(planTaskForm.getTaskfinishtime())+" 23:59:59"); } } PlanTask.setTastcontent(URLDecoder.decode(planTaskForm.getTastcontent(),"utf-8")); PlanTask.setResponsibleperson(URLDecoder.decode(planTaskForm.getResponsibleperson(),"utf-8")); PlanTask.setAttr1("false"); PlanTask.setAttr2(planTaskForm.getAttr2()); PlanTask.setAttr3(userID); PlanTask.setFinishtype(URLDecoder.decode(planTaskForm.getFinishtype(),"utf-8"));     response.getWriter().print("ok");

} }catch(Exception e){ e.printStackTrace(); }

转载请注明原文地址: https://www.6miu.com/read-52598.html

最新回复(0)