Home > Article > Web Front-end > JQuery uses $.ajax and checkbox to implement the next absence notification function
This article mainly introduces JQuery's use of $.ajax and checkbox to implement the next absence notification function. This article gives complete examples of HTML code, JS code, and back-end JAVA code. Friends in need can refer to it
XXX platform wants to implement a function, use the check box on the announcement pop-up page to no longer notify such announcements.
Principle: 7b966fa1cac79bb6e40b7ac145b8ac9f, submit the form after the checkbox is selected , then the isSelect in the struts2 Action is '10', and if the submit form is not selected, the isSelect is null.
1.jsp page
<form id="form1"> <p class="jf_tanchu"> <p class="jf_tanchutit">${ bussinessNotice.noticeTitle}</p> <p class="jf_tanchubox"> <p class="jf_tanchubox_right"> 公告类型:<v:dcolor code="${ bussinessNotice.noticeType}"/> 发布时间:<fmt:formatDate value="${ bussinessNotice.createDate}" pattern="yyyy-MM-dd"/> </p> ${bussinessNotice.noticeInfo} </p> </p> <s:if test="bussinessNotice.noticeType=='25'||bussinessNotice.noticeType=='63'||bussinessNotice.noticeType=='64'"> <p> <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> </p> </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()); } }
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
jQuery and ajax implement mouse click to modify content
jquery address bar link and a Special effects for tag link matching
The above is the detailed content of JQuery uses $.ajax and checkbox to implement the next absence notification function. For more information, please follow other related articles on the PHP Chinese website!