JQuery USES $.ajax and checkbox for the next no notice feature

  • 2020-05-30 19:20:54
  • OfStack

To implement one function on the XXX platform, you will no longer be notified of such announcements using the checkbox Settings on the announcement pop-up page.

Principle: < input type="checkbox" id="isSelect" name="isSelect" value="10" onclick="javascript:noTips();"/ > , checkbox is selected to submit the form, then isSelect in Action of struts2 is '10', and isSelect is null to submit the form unselected.

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"> 
     Type of announcement: <v:dcolor code="${ bussinessNotice.noticeType}"/>&nbsp;&nbsp;&nbsp;&nbsp; 
     Post date: <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"> No further notice of such announcements </label> 
</div> 
</s:if> 
</form> 

2. js code


 function noTips(){ 
  var formParam = $("#form1").serialize();// Serialize the table contents as a string  
  $.ajax({ 
    type:'post',   
    url:'Notice_noTipsNotice', 
    data:formParam, 
    cache:false, 
    dataType:'json', 
    success:function(data){ 
    } 
  }); 
} 
 

3. NoticeAction code


/** 
 * checkbox No notice is prompted, need to be modified TBussinessSet The shielded state in, ajax An asynchronous request  
 */ 
public void noTipsNotice(){ 
  try { 
    PrintWriter out = this.getResponse().getWriter(); 
     
    bussinessSet = BussinessSetService.queryById(getUserId()); 
    String state = ""; 
    if(isSelect==null){//noticeType==null There is no selected 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()); 
  } 
} 

Related articles: