zoukankan      html  css  js  c++  java
  • AJAX 前后端交互 验证信息是否正确

    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     }
  • 相关阅读:
    剑指 Offer 42. 连续子数组的最大和
    剑指 Offer 41. 数据流中的中位数
    剑指 Offer 40. 最小的k个数
    剑指 Offer 39. 数组中出现次数超过一半的数字
    20210510日报
    20210507日报
    20210506日报
    20210505日报
    20210504日报
    20210503日报
  • 原文地址:https://www.cnblogs.com/wangzh1guo/p/9962310.html
Copyright © 2011-2022 走看看