日期:2014-05-16  浏览次数:20691 次

jQuery+Ajax+Struts1例子
    public ActionForward validateLoginId(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String loginId = request.getParameter("login_id");
        String status = "1";
    	if(RmStringHelper.checkNotEmpty(loginId)){
    		List<RmCommonVo> resultList = null;
    		resultList=RmProjectHelper.getCommonServiceInstance().doQuery("select ID from RM_USER  where USABLE_STATUS='1' and LOGIN_ID='"+loginId+"'");
    		if(resultList.size()==0){
    			status = "0";
    		}
    	}
    	response.getWriter().print(status);
        return null;
    }

?

function validateLoginId(){
		var sValue = true;
		$.getJSON("<%=request.getContextPath()%>/RegisterUserAction.do?cmd=validateLoginId", 
			{
				login_id:$("#login_id").val()
			}, 
			function(data){
				if(data == '1') {
					//alert("登录账号重复!");
					writeValidateInfo("登录账号已被使用,请重新输入!",document.getElementById("login_id"));
					sValue = false;
				}else{
					writeValidateInfo("",document.getElementById("login_id"));
					sValue = true;
				}
			});
		return sValue;
	}
?