Ajax implements the login form verification function and ajax implements Form Verification

Source: Internet
Author: User

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.