ajax后台校验返回结果给前端
程序员文章站
2022-06-03 23:13:29
...
1.发送请求并传递参数 $.ajax({ url: ctx + "mes/flowinfo/itemsExists?itemId="+row.itemId+"&progId="+progId, type: 'post',//提交类型 //data: { "itemId": row.itemId, "progId": progId }, //参数都是以JSON方式传递 async: false,//true为异步,false为同步 contentType: "application/json", dateType: "json", success: function(data) { if ( data.EXISTS == 'Y' ) { $.modal.alertError("章节已经存在列表中!"); } else { $.operate.post(ctx + "dfm/configenum/addFmNode", { "itemId": row.itemId, "progId": progId } ,function () { //刷新列表 $.modal.msgSuccess("添加成功"); $.table.refresh(); $.modal.closeLoading(); }); } } }) 2.后台代码,返回JSON格式,这里用的是fastjson工具 @PostMapping({"/itemsExists"}) @ResponseBody public JSONObject ifItemIdExists(Long itemId,Long progId) { FmFlowConfigInfo fmFlowConfigInfo = new FmFlowConfigInfo(); fmFlowConfigInfo.setItemId(itemId); fmFlowConfigInfo.setProgId(progId); List<FmFlowConfigInfo> fmFlowConfigList = this.fmFlowConfigInfoService.selectFmFlowConfigInfoList(fmFlowConfigInfo); JSONObject jsonObject = new JSONObject(); String exists = fmFlowConfigList.size() > 0 ? "Y" : "N"; jsonObject.put("EXISTS",exists); return jsonObject; }
上一篇: 突然发现这周有点忙。。着玩-PHP进阶
下一篇: 完美Email验证正则表达式