$.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中的相关信息:
</td>
<td align="left" width="20%" nowrap="nowrap" id="idUserRequiredMsgtd"> </td>
<td id="ajaxValidateExittd" width="20%" nowrap="nowrap"></td>
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;
}
}