关于Ajax实例

其中封装了很多的东西。比如layer弹框,当中还包含了一个弹框输出的操作,如果确定就进行Ajax的操作;
var status1 = $("#STATUS_"+attrId).val();
还有这一句话,实际上id=STATUS,用的是里面进行保存,用于记录相关状态,这是丁大哥教我的,实际上就是使用jQuery的时候取相关节点的状态更方便。
编码为权限代号

<shiro:hasPermission name="SXGW005">
		<button type="button" class="gy_btn fh_btn" toptitle='失效' id="unable" name="unable" onclick="del(99,this);return false;"><i class="iconfont"> &#xe617;</i> 失效<tton>&nbsp;&nbsp;
		<iro:hasPermission>
		<shiro:hasPermission name="SXGW006">
		<button type="button" class="gy_btn fh_btn" toptitle='恢复' id="enable" name="enable" onclick="del(10,this);return false;"><i class="iconfont"> &#xe60c;</i> 恢复<tton>&nbsp;&nbsp;
<shiro:hasPermission>

function del(status,Obj){
		//var checkbox = document.getElementsByName("baseId");
		var a = 0;
		var attrId,ds;
		var operationName = $(Obj).attr("toptitle");
		 $(":checkbox:checked").each(function(){   
			    a++;
			    attrId = $(this).val();
		  })
		  console.log(ds);
		if(a!=1){
			layer.alert("请选择一条记录!",{icon:7});
			return false;
		}
		//status1是临时加上去的,目的是获取到状态当中的文本信息,接下来好做一个判断!
		var status1 = $("#STATUS_"+attrId).val();
		 if(status ==10 && status1 == 10){//恢复操作
				layer.alert("该记录已是有效状态!",{icon:7});
				return false; 
			}
			if(status ==99 && status1==99){//失效操作
				layer.alert("该记录已是无效状态!",{icon:7});
				return false;  
			} 
		layer.confirm("确定"+operationName+"吗?",{btn:['确定','取消']},function(){
			$.ajax({
			    type: "POST",
			    url: "${ctx}/sd/attr/euable.do",
			    data: {attrId:attrId,dataState:status},
				dataType : "json",
				success: function(data) {
					if(data == 1) {
						layer.alert("恢复成功",{icon:1},function(){
							window.location.reload();
							});
					} else {
						layer.alert("失效成功",{icon:2},function(){
							window.location.reload();
						});
					}
				},
				error: function(data) {
					layer.alert(operationName+"异常",{icon:2});
				}
			});
		},function(){
			
		})
	} 

controller层中代码示例

 * 账套环节恢复与失效界面操作
	 * 
	 */
	@RequestMapping(value="/euable")
	@ResponseBody
	public String del(HttpServletRequest request,CorpSegment corpSeBean) {
		String result="";
		try {
			if ("10".equals(corpSeBean.getDataState())) {
				corpSegService.recoverCorpSeById(corpSeBean.getId());
				result="1";
			}else {
				corpSegService.invalidCorpSe(corpSeBean.getId());
				result="0";
			}
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			result=e.getMessage();
		}catch (Exception e) {
			// TODO: handle exception
			logger.error("出现异常!");
		}
		return result;
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值