ajax提交并根据返回的值重写标签
Jsp:
function saveCalendar(id){ var startTmDetail = $("#startTimeDetail"+id).val(); var startHour = $("#startHour"+id).val(); var endTmDetail = $("#endTimeDetail"+id).val(); var endHour = $("#endHour"+id).val(); var content = $("#contentDetail"+id).val(); var param = [ {name:'startTmDetail', value:startTmDetail}, {name:'startHour', value:startHour}, {name:'endTmDetail', value:endTmDetail}, {name:'endHour', value:endHour}, {name:'content', value:content}, {name:'id', value:id} ]; $.ajax({ type: 'post', url: '<%=path %>/calendarInfo/updateCalDetail.action', async: false,//想要执行完这个ajax再执行下边代码,就要设置成false data: param, dataType: 'text', success: function(text){ var jsonObj = eval("("+text+")"); var divStr = ""; var divContent = ""; //重写divStr divStr = "<div id='showTm"+jsonObj.id+"'>"+jsonObj.startTime+" 到 "+jsonObj.endTime+" <input style='border: 1px solid #777;' type='button' value='编辑' onclick='calendarEdit("+jsonObj.id+")' /></div>"; divContent = "<div id='showContent"+jsonObj.id+"'>"+jsonObj.content+"</div>"; $("#showTm"+id).html(divStr); $("#showContent"+id).html(divContent); $("#showTm"+id).show(); $("#hidTm"+id).hide(); $("#showContent"+id).show(); $("#hidContent"+id).hide(); }, error: function(text) { alert('失败'); } }); }
Action:
@RequestMapping("/calendarInfo/updateCalDetail") public void updateCalDetail(HttpServletResponse res,HttpServletRequest request) throws Exception{ res.reset(); res.setContentType("text/html;charset=utf-8"); PrintWriter pw = res.getWriter(); String id = request.getParameter("id"); String startTm = request.getParameter("startTmDetail"); String startHour = request.getParameter("startHour"); String endTm = request.getParameter("endTmDetail"); String endHour = request.getParameter("endHour"); String content = request.getParameter("content"); String startStr = startTm + " " +startHour + ":00:00"; String endStr = endTm + " " +endHour + ":00:00"; CalendarDetail calDetail = new CalendarDetail(); calDetail = calDetailService.findCalendarDetailById(Long.parseLong(id)); calDetail.setStartTime(startStr); calDetail.setEndTime(endStr); calDetail.setContent(content); calDetailService.update(calDetail); JSONObject jsonObject = JSONObject.fromObject(calDetail); System.out.println(jsonObject); pw.print(jsonObject); pw.flush(); pw.close(); }
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05