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     }
  • 相关阅读:
    进度条
    html5 表单新增事件
    html5 表单的新增type属性
    html5 表单的新增元素
    html5 语义化标签
    jq 手风琴案例
    codeforces 702D D. Road to Post Office(数学)
    codeforces 702C C. Cellular Network(水题)
    codeforces 702B B. Powers of Two(水题)
    codeforces 702A A. Maximum Increase(水题)
  • 原文地址:https://www.cnblogs.com/wangzh1guo/p/9962310.html
Copyright © 2011-2022 走看看