Ajax implements the login form verification function and ajax implements Form Verification
Ajax implements the login form verification function:
The form login verification function using ajax is more user-friendly. The following provides an example code for form verification. The code is simple and only used for demonstration, multiple practical ajax form verification functions are complex. The following code is distributed:
I. Static Page form code:
<Script type = "text/javascript" src = "http://www.softwhy.com/mytest/jQuery/jquery-1.8.3.js"> </script> <script type = "text/javascript" src = "jslib/verify. js "> </script>
Pay attention to the reference to the jQuery library file, and form submission without using form in ajax.
Ii. verify. js code:
function verify() { var paramObj=encodeURI(encodeURI($( "#username" ).val())); $.get( "TestSvlt?username=" +paramObj, null ,callback); } function callback(data) { var resultObj=$( "#result" ); resultObj.html(data); }
3. Create a servlet: AjaxLogin class; write it in the doGet method:
response.setContentType( "text/html;charset=utf-8" ); PrintWriter out=response.getWriter(); String name=request.getParameter( "username" ); String username= URLDecoder.decode (name, "UTF-8" ); System. out .println(username); if( null ==username|| "" .equals(username)) { out.print( "username is not null" ); } else { if (! "lej" .equals(username)) { out.print(username+ " not existing" ); } else { out.print(username+ " login successs" ); } }
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 7886 # pid1_85
For more information, see: http://www.softwhy.com/jquery/