Home >Web Front-end >JS Tutorial >JQuery uses $.ajax and checkbox to implement the next absence notification function_jquery
XXX platform wants to implement a function, use the check box on the announcement pop-up page to set no notification of such announcements.
Principle: 7b966fa1cac79bb6e40b7ac145b8ac9f, submit the form after the checkbox is selected, then in the Action of struts2 isSelect is '10', if the submit form is not selected, isSelect is null.
1.jsp page
<form id="form1"> <div class="jf_tanchu"> <div class="jf_tanchutit">${ bussinessNotice.noticeTitle}</div> <div class="jf_tanchubox"> <div class="jf_tanchubox_right"> 公告类型:<v:dcolor code="${ bussinessNotice.noticeType}"/> 发布时间:<fmt:formatDate value="${ bussinessNotice.createDate}" pattern="yyyy-MM-dd"/> </div> ${bussinessNotice.noticeInfo} </div> </div> <s:if test="bussinessNotice.noticeType=='25'||bussinessNotice.noticeType=='63'||bussinessNotice.noticeType=='64'"> <div> <input type="hidden" name="noticeType" value="${bussinessNotice.noticeType}"/> <input type="checkbox" id="isSelect" name="isSelect" value="${bussinessNotice.noticeType}" onclick="javascript:noTips();"/> <label for="isSelect">不再通知此类公告</label> </div> </s:if> </form>
2.js code
function noTips(){ var formParam = $("#form1").serialize();//序列化表格内容为字符串 $.ajax({ type:'post', url:'Notice_noTipsNotice', data:formParam, cache:false, dataType:'json', success:function(data){ } }); }
3.NoticeAction code
/** * checkbox不提示公告,需要修改TBussinessSet中的屏蔽状态,ajax异步请求 */ public void noTipsNotice(){ try { PrintWriter out = this.getResponse().getWriter(); bussinessSet = BussinessSetService.queryById(getUserId()); String state = ""; if(isSelect==null){//noticeType==null没有选中checkbox state = "11"; } else{ state = "10"; } if("25".equals(noticeType)){ bussinessSet.setSaleBack(state); } else if("63".equals(noticeType)){ bussinessSet.setRemittanceBank(state); } else if("64".equals(noticeType)){ bussinessSet.setRemittanceOnline(state); } BussinessSetService.update(bussinessSet); out.print(""); } catch (Exception e) { log.error(e.fillInStackTrace()); } }