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)