JQuery使用$.ajax和checkbox實現下次不在通知功能,jquery.ajax

來源:互聯網
上載者:User

JQuery使用$.ajax和checkbox實現下次不在通知功能,jquery.ajax

XXX平台要實現一個功能,公告彈出頁面上使用複選框設定不再通知此類公告。
 
原理:<input type="checkbox" id="isSelect" name="isSelect" value="10" onclick="javascript:noTips();"/>,checkbox選中後提交表單,那麼struts2的Action中isSelect就為'10',不選中提交表單isSelect為null。
 
1.jsp頁面

<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代碼

 function noTips(){   var formParam = $("#form1").serialize();//序列化表格內容為字串   $.ajax({     type:'post',       url:'Notice_noTipsNotice',     data:formParam,     cache:false,     dataType:'json',     success:function(data){     }   }); }  

 3.NoticeAction代碼

/**  * 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());   } } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.