1、前段:
1 function checkPtCode(obj){ 2 $.ajax({ 3 type: "post", 4 url: "xxxxxxx", 5 data: {"xx":obj.value}, 6 cache: false, 7 async : true, 8 dataType:"json", 9 type:"POST", 10 success: function (result){ 11 if(result.flag == "No"){ 12 jAlert("编码库不存在此编码,请修正!"); 13 } 14 } 15 }); 16 }
2、后端
1 public void checkPtCode(HttpServletRequest request, 2 HttpServletResponse response) throws IOException { 3 PrintWriter out = response.getWriter(); 4 JSONObject json = new JSONObject(); 5 try { 6 response.setContentType("text/html;charset=UTF-8"); 7 response.setContentType("text/html"); 8 response.setHeader("Cache-Control", "no-store"); 9 response.setHeader("Pragma", "no-cache"); 10 response.setDateHeader("Expires", 0); 11 String ptCode = request.getParameter("ptCode"); 12 13 if(ptCode != null && ptCode.trim().length() != 0){ 14 // 编码库校验 15 List<DrpProductType> list = this.controlRelationService.checkCode(ptCode); 16 if(list != null && list.size() != 0){ 17 json.put("flag", "ok"); 18 out.print(json.toString()); 19 }else { 20 json.put("flag", "No"); 21 out.write(json.toString()); 22 } 23 } 24 } finally { 25 out.close(); 26 } 27 }