Jquery.validate Authentication (supports front-end JS verification via, then Ajax background data check)

Source: Internet
Author: User

Download the jquery-validation-1.13.1 demo package.

See jquery-validation-1.13.1\demo\milk\index.html This example is good, verify successfully hit a checkmark. Then look at the background JS Code discovery

<script src= ". /.. /lib/jquery.mockjax.js "></script> What is this, originally this is used to imitate the service-side verification of JS, analog corresponding message. As follows:

$.mockjax ({
URL: "Emails.action",
Response:function (Settings) {
var email = settings.data.email,
emails = ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"];
This.responsetext = "true";
if ($.inarray (email, emails)!==-1) {
This.responsetext = "false";
}
},
responsetime:500
});

The text box Id to verify is email, so the URL here is "emails.action". (Why not email, see below:)

var validator = $ ("#signupform"). Validate ({
Rules: {
Email: {
Required:true,
Email:true,
Remote: "Emails.action"
}

..........

It is the email attribute above to define a remote to support long-range server authentication.

The above is all nonsense (I do not need to simulate the server, I just use the server AH)

Then refer to the following:

Http://www.cnblogs.com/xiawuyi/archive/2013/04/01/2990224.html a case of MVC.

Http://jqueryvalidation.org/remote-method/the official example.

My example:

First find the Jquery.validate.js file find DataType: "JSON" and then comment on this line of code (I do not know why it does not want to support JSON, not the default text, or return data format customization is not good?)

Some of the code is as follows:

<link href= "Plug/bootstrap/bootstrap.css" rel= "stylesheet"/> You can use it.
<script src= "Js/jquery.min.js" ></script>
<script src= "Plug/bootstrap/dist/js/bootstrap.js" ></script> you don't have to.
<script src= "Plug/jquery-validation/dist/jquery.validate.js" ></script>

<input type= "text" runat= "server" class= "Form-control" data-rule-email= "true" Name= "Inputemail" id= "Inputemail"

Data-msg-email= "Please enter the correct email address" placeholder= "Retrieve password and register to verify credentials passed" data-error= "Sssss" required>

$ (document). Ready (function () {
var validator = $ ("#form1"). Validate ({
Rules: {
Inputemail: {
Remote: {
Url:window.location.pathname, type: "Post",
Data: {
Inputemail:function () {
Return $ ("#inputEmail"). Val ();
}
}
}
}
}
})
});

if (request.form["Inputemail"]! = NULL)
{
Response.Write (111); It's good to define the verification method here.
Response.End ();
}

Jquery.validate Authentication (supports front-end JS verification via, then Ajax background data check)

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.