• Jquery ajax json 验证用户名是否存在


    服务器(Terasoluna框架)json的方式响应客户端      

    1)客户端jquery相关代码:      
    $("#idUser").blur(function(){
                    $.post("a_usr_s03_ValidateUserIdAjaxBL.do",
                            {"idUser":$("#idUser").val(),  //需要验证的值

                            "validate_exit_msg":$("#validate_exit_msg").val()}, //当存在时返回的data(key:value)
                            function(date){          //回调函数
                                if(date!=null&&date!=""){
                                    $("#idUserRequiredMsgtd").hide();
                                    $("#ajaxValidateExittd").show().html(date);
                                    $("#idUser").css({"border":"1px solid red"});
                                    $(".btnSave").attr("disabled",true);
                                }else{
                                    $("#idUser").css({"border":"1px solid #DBDFE6"});
                                    $(".btnSave").removeAttr("disabled");
                                }
                    });
                });
                $("#idUser").focus(function(){
                    $("#idUserRequiredMsgtd").show();
                    $("#ajaxValidateExittd").hide();
                });

    jsp中的相关信息:

    <input type="hidden" value="<bean:message key="errors.a_usr_s03.error1" />" id="validate_exit_msg" />  隐藏消息,当idUser存在时显示此消息
     
    <td align="left" width="25%"><input type="text" id="idUser" class="disabled" name="idUser" maxlength="12" style=" 90%;background-color: white" value="<bean:write name="a_usr_s02Form" property="idUser" />" />
    </td>
     <td align="left" width="20%" nowrap="nowrap" id="idUserRequiredMsgtd">&nbsp;</td>
    <td id="ajaxValidateExittd" width="20%" nowrap="nowrap"></td>
           2)服务器端相关代码:
    public class A_USR_S03_ValidateUserIdAjaxAction extends ActionEx {
        
        private QueryDAO queryDAO;

        /* (non-Javadoc)
         * @see jp.terasoluna.fw.web.struts.actions.ActionEx#doExecute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
         */
        @Override
        public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                HttpServletResponse response) throws Exception {
            PrintWriter out = response.getWriter();
            List<A_USR_S03_User> listUser = new ArrayList<A_USR_S03_User>();
            if(request.getParameter("idUser").trim()!=null&&request.getParameter("idUser").trim()!=""){
                String idUser=StringUtil.trim(request.getParameter("idUser")).toUpperCase();
                listUser = queryDAO.executeForObjectList("SELECT.A_USR_S03.CHECK_IDUSER", idUser);
            }
            if(listUser.size()==1){
                String message="<img src='../image/error.png'/><font color='red'>";
                message+=StringUtil.trim(request.getParameter("validate_exit"));
                message+="</font>";
                out.print(message);
                System.out.println(message);
                out.close();
            }
            return null;
        }

        public QueryDAO getQueryDAO() {
            return queryDAO;
        }

        public void setQueryDAO(QueryDAO queryDAO) {
            this.queryDAO = queryDAO;
        }
    }
  • 相关阅读:
    农民没有钱,怎样从种植养殖方面创业?
    有几万闲钱,投资什么好?
    2019适合创业的项目有哪些呢
    1981年的五块钱相当于现在多少钱的购买力?
    现阶段有50万资金,想去开一个店,从事什么行业好?
    投资40万左右适合做什么?
    阿里联手百联打造新零售,耗巨资10亿成立便利店
    90后,是被逼创业的,大家觉得呢?
    小本创业,具体怎么办?
    (三)调用web服务
  • 原文地址:https://www.cnblogs.com/chengfang/p/Jquery_ajax_json.html
Copyright © 2020-2023  润新知