欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

点击按钮后通过Ajax请求判断后台,若成功则执行操作,若失败则弹出提示对话框

最编程 2024-01-09 07:10:42
...

本人想实现一个功能,在点击出库按钮时加以判断是否可以出库,如果不能出库提示操作者该操作不能进行

1 首先做一个按钮点击事件

<a class="label xiugai" id="chuku" onclick="dianjichuku(${(XSaleCommodity.saleCommodityId)?string("#")!''})" >
                                        <span class="glyphicon glyphicon-log-out" style="font-size:13px">出库</span>
                                    </a>

2js 代码

function dianjichuku(obj){
        debugger;
        $.post("pdcbenhesuan",{id:obj},function (data) {   // 路径跳转到后台做判断
        debugger;
            if(data=="未做成本核算,暂不能出库"){
                alert("未做成本核算,暂不能出库")
            }else{
                alert("成本已核算")
                //判断成本核算过后超链接到后台继续完成出库操作
                // window.location.href="editoutStatus?id="+id;
                window.location.href="editoutStatus?id="+obj;
            }
        })
    }

3 后台代码

/判断成品出库钱先判断是否进行过成本核算
    @RequestMapping(value = "pdcbenhesuan", method = RequestMethod.POST)
    public @ResponseBody String pdcbenhesuan(@RequestParam(value = "id", required = false) Long id
                               ) throws ParseException {
 if(goodsPriceList==null || cangkushu!=goodsNums) {
        return "未做成本核算,暂不能出库";
        }else {
            return "可以出库";
       }
}

原文地址:https://www.cnblogs.com/pdxt666/p/16075925.html