<td id="show_<s:property value='infoId'/>" align="center"><s:property value="state==1?'发布':'停用'"/></td> <td align="center"> <span id="oper_<s:property value='infoId'/>"> <s:if test="state==1"> <a href="javascript:doPublic('<s:property value='infoId'/>',0)">停用</a> </s:if><s:else> <a href="javascript:doPublic('<s:property value='infoId'/>',1)">发布</a> </s:else> </span> <a href="javascript:doEdit('<s:property value='infoId'/>')">编辑</a> <a href="javascript:doDelete('<s:property value='infoId'/>')">删除 </a> </td>
//异步发布信息,信息的id以及将要改成的状态值 function doPublic(infoId,state){ //1.更新信息状态 $.ajax({ url:"${basePath}tax/info_publicInfo.action", data:{"info.infoId":infoId,"info.state":state}, type:"post", success:function(msg){ //2.更新状态栏,操作栏的显示值 if("更新状态成功"==msg){ if(state==1){ //说明信息状态已经被改成发布,操作栏被改为停用 $("#show_"+infoId).html("发布"); $("#oper_"+infoId).html('<a href="javascript:doPublic(\''+infoId+'\',0)">停用</a>'); }else{ $("#show_"+infoId).html("停用"); $("#oper_"+infoId).html('<a href="javascript:doPublic(\''+infoId+'\',1)">发布</a>'); } }else{ alert("更新信息状态失败!"); } }, error:function(){ alert("更新信息状态失败!"); } }); }
//异步发布信息 public void publicInfo(){ try { if (info != null) { //1.更新信息状态 Info tem = infoService.findObjectById(info.getInfoId()); tem.setState(info.getState()); infoService.update(tem); //2.输出更新结果 HttpServletResponse response = ServletActionContext .getResponse(); response.setContentType("text/html"); ServletOutputStream outputStream = response.getOutputStream(); outputStream.write("更新状态成功".getBytes("utf-8")); outputStream.close(); } } catch (Exception e) { e.printStackTrace(); } }
至此我们的异步信息发布/停用状态更改功能完成!
转载请注明出处:http://blog.csdn.net/acmman/article/details/49741475