JqueryFormvalidator Ajax modify the data to verify whether the data exists

Source: Internet
Author: User

Var accErrorMsg = "Enter the customer category name ";
// Verify form data
$ (Function (){
// $. FormValidator. initConfig ({formid: "myform", autotip: true });
$. FormValidator. initConfig ({
Formid: "myform ",
Autotip: true
});

$ ("# Name"). formValidator ({
Onshow: "Enter the customer category name ",
Onfocus: "2 to 20 characters ",
Oncorrect: "correct input"}). functionValidator ({
Fun: function (){
Var roleName = $ ("# name"). val ();
If (trim (roleName) = "")
{
AccErrorMsg = "Enter the customer category name ";
Return accErrorMsg;
} Else if (trim (roleName). length = 1 | trim (roleName). length> 20 ){
AccErrorMsg = "2 to 20 characters ";
Return accErrorMsg;
}
Else
{
Return true;
}
}
}). AjaxValidator ({
Type: "post ",
Url: "$ {basePath} clientSortSTManage/clientSortST! IsClientSortNameExist. action ",
Datatype: "json ",
Timeout: 3000,
Success: function (data)
{
// Compare the old role name with the new role name.
Var oldName = $ ('# oldname'). val ();

Var rName = $ ('# name'). val ();
If (oldName & oldName = rName)
{
Return true;
}

// Determine based on ajax return results
Var correct = data. correct;
If (correct)
{
Return true;
}
Else
{
Return false;
}


},
Error: function ()
{
Artalert ("the service is busy. Please try again later! ");
},
Onerror: "The customer category name already exists. Please change the customer category name ",
Onwait: "The customer category name is being verified. Please wait... "
}). DefaultPassed ();
})
 
This article is from the "Coffee Hou ye" blog

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.