Jquery.validate uses remote to implement AJAX validation paradigm

Source: Internet
Author: User
Jquery.validate is a powerful form verification plug-in, of course, also perfect support for Ajax validation, so that it can be convenient, fast to check the user name, etc. exist.

Html/js Source section:
<form action= "" Name= "Infos" id= "Infos" >

<p> User name: <input type= "text" name= "username" id= "username"/></p>

<p><input type= "Submit" Name= "Sub"/></p>

</form>

<script type= "Text/javascript" >

$ (function () {

$ (' #infos '). Validate ({

Debug:false,

Onkeyup:false,

rules:{

username:{

Required:true,

remote:{

Type: "POST",

URL: "ajax.php",//Request address

data:{

Username:function () {return $ ("#username"). Val ();

}

}

}

},

messages:{

username:{

Required: "User name must be filled in",

Remote: "User name already exists"

}

},

Submithandler:function (form) {

Alert ("Validation passed");

}

});

});

</script>

PHP Source section:

<?php

if ($_request[' username '] = = ' php ')

{

Exit ("false"); User name already exists

}

Else

{

Exit ("true"); User name does not exist, validation passes, output "true", and End program

}

?>

Example Run Effect:

Note that when the server output is true or false, do not output directly, enclose in quotation marks (as shown above)
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.