|
|
jquery ajax校验
/**************jquery ajax校验***************************************************/function onclickXml(name){ var hotelId=$("#hotelId").val(); if(name.value ==''||name.value.length==0){alert('输入的用户名为空!'); return false; } else { alert("aaaaa"); $.ajax({ type: "POST", url: "<%=request.getContextPath()%>/hotelManage.do?method=ajaxValidateName", data: "uname="+name.value, success: function(msg){ alert(msg); } }); } }
prototype ajax校验
/**************prototype ajax校验***************************************************/ function validateName(name){ var url="<%=request.getContextPath()%>/hotelManage.do?method=ajaxValidateName"; var pars="hotelId="+encodeURI(encodeURI($("#hotelId").val()))+"&name="+encodeURI(encodeURI(name.value));//解决中文乱码问题 var myAjax = new Ajax.Request( url, { method: 'post', parameters: pars, onComplete: showResponse }); }function showResponse(originalRequest){ // var tt = originalRequest.responseText; alert(originalRequest.responseText); // $("#loading").html("<font color='red'>该名称已存在!</font>"); // $("#loading").show(); }
jsp代码
<input type="hidden" name="hotelId" id="hotelId" value="<c:out value='${hotelId}'/>"/> 名称:<input name="name" id="name" value="" type="text" size="16" /><!--onclickXml(this) -->
后台action
public ActionForward ajaxValidateName(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception{HotelBusIface service = (HotelBusIface) this.getObject();String name = URLDecoder.decode(request.getParameter("name"),"UTF-8");String hotelId = request.getParameter("hotelId");PrintWriter out = response.getWriter();System.out.println(name+"-----"+hotelId);if(service.existImageName(hotelId, name)){System.out.println("exist");out.println("exist");}else{System.out.println("noexist");out.println("noexist");} return null;} |
|