ajax表单验证后台用户名是否存在

前端之家收集整理的这篇文章主要介绍了ajax表单验证后台用户名是否存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. @H_404_15@
  1. //以下是ajax部分@H_404_15@
  2. varxmlhttp;@H_404_15@
  3. @H_404_15@
  4. functionajaxfun()@H_404_15@
  5. {@H_404_15@
  6. @H_404_15@
  7. if(window.XMLHttpRequest)@H_404_15@
  8. {//codeforIE7+,Firefox,Chrome,Opera,Safari@H_404_15@
  9. xmlhttp=newXMLHttpRequest();@H_404_15@
  10. }@H_404_15@
  11. else@H_404_15@
  12. {//codeforIE6,IE5@H_404_15@
  13. xmlhttp=newActiveXObject("Microsoft.XMLHTTP");@H_404_15@
  14. }@H_404_15@
  15. returnxmlhttp;@H_404_15@
  16. }@H_404_15@
  17. @H_404_15@
  18. window.onload=function()@H_404_15@
  19. {@H_404_15@
  20. @H_404_15@
  21. document.getElementById("username1").onblur=function()@H_404_15@
  22. {@H_404_15@
  23. varname=document.getElementsByName("username")[0].value;@H_404_15@
  24. xmlhttp=ajaxfun();@H_404_15@
  25. xmlhttp.onreadystatechange=check;@H_404_15@
  26. //xmlhttp.open("get","http://localhost:8080/ajaxtest/AjaxServlet?username="+name+"&time="+newDate().toTimeString(),true);@H_404_15@
  27. //以下是get方法传值@H_404_15@
  28. /*xmlhttp.open("get","./AjaxServlet?username="+name+"&time="+newDate().toTimeString(),true);@H_404_15@
  29. xmlhttp.send(null);*/@H_404_15@
  30. @H_404_15@
  31. /*@H_404_15@
  32. *如果需要像HTML表单那样使用POST传递数据,请使用setRequestHeader()来添加HTTP头。@H_404_15@
  33. *然后在send()方法中规定您希望发送的数据:@H_404_15@
  34. */@H_404_15@
  35. xmlhttp.open("post",true);@H_404_15@
  36. xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")@H_404_15@
  37. xmlhttp.send("a=100&b=222");@H_404_15@
  38. @H_404_15@
  39. }@H_404_15@
  40. @H_404_15@
  41. }@H_404_15@
  42. functioncheck()@H_404_15@
  43. {@H_404_15@
  44. alert(xmlhttp.status);@H_404_15@
  45. if(xmlhttp.readyState==4&&xmlhttp.status==200)@H_404_15@
  46. {@H_404_15@
  47. alert(xmlhttp.status);@H_404_15@
  48. document.getElementById("span").innerHTML=xmlhttp.responseText;@H_404_15@
  49. }@H_404_15@
  50. }@H_404_15@
  1. //jsp中的body部分@H_404_15@
  2. <body>@H_404_15@
  3. <%--<formaction="/ajaxtest/RegisteServlet"method="get">@H_404_15@
  4. <formaction=""method="get"enctype="application/x-www-form-urlencoded">@H_404_15@
  5. --%>@H_404_15@
  6. <formaction="/ajaxtest/RegisteServlet"method="get">@H_404_15@
  7. 用户名:<inputtype="text"name="username"id="username1"/><spanid="span"></span><br>@H_404_15@
  8. 密码:<inputtype="password"name="userpass"/><br>@H_404_15@
  9. 确认密码:<inputtype="password"name="userpass2"/><br>@H_404_15@
  10. <inputtype="submit"value="提交"/>@H_404_15@
  11. @H_404_15@
  12. <inputtype="button"name="username"id="username1"value="点击"/>@H_404_15@
  13. </form>@H_404_15@
  14. </body>@H_404_15@

猜你在找的Ajax相关文章