ajax校验用户名是否存在
1.前端页面
<input name="USERID" type="text" id="USERID" /> //校验用户名是否存在 <script> $("#USERID").blur(function(){ var USERID = $(this).val(); $.ajax({ url: "checkUserName.jsp", type: "POST", data:{"USERID":USERID}, dataType: "text", async: false,//同步执行 //error: function(){alert("erro");}, success: function(data){ if(data == 1){ $("#erroInfo").next("span").hide(); $("#erroInfo").show(); $("#erroInfo").html(" 用户名已存在,请重新输入!"); }else{ $("#erroInfo").next("span").show(); $("#erroInfo").hide(); } } }); }); </script>2.java编写后台处理
String USERID=request.getParameter("USERID"); String strSQL = "select * from d_zwuser where userid = '"+USERID+"'"; DBService dbservice = new DBService(); String result = ""; DBSet dbset = dbservice.getSelectSet(strSQL); if(dbset.size() > 0){ //result = " 用户名已存在,请重新输入!"; result="1"; } response.getWriter().flush(); response.setCharacterEncoding("utf-8"); response.getWriter().print(result); response.getWriter().flush();
相关推荐
胡献根 2020-07-05
troysps 2020-06-13
shayuchaor 2020-06-10
dengweijunkedafu 2020-06-09
Andrew代码战士 2020-06-08
TONIYH 2020-05-25
PlumRain 2020-05-10
Cloudeep 2020-04-15
inhumming 2020-04-10
末点 2020-03-06
hpujsj 2020-03-03
airfling 2020-03-01
ITfooter 2020-02-23
Justdoit00 2020-02-16