Remote verification experience with Bootstrapvalidator

Source: Internet
Author: User

Here it is necessary to say that Bootstrapvalidator's help document is relatively simple to write, especially for remote validators, and after a multi-party test, it is not clear how to use this validator.

A typical Ajax validation code is as follows:

The server-side validation code (using spring MVC) is as follows:

/** Returns the result of string type * Check the legality of user name, return False if user already exists, otherwise return True (return JSON data, format {"Valid", true})*/@RequestMapping (Value= "/checknameexistsmethod1", produces = "Application/json;charset=utf-8")     Public@ResponseBody string checkNameValidMethod1 (@RequestParam string name) {Booleanresult =true; List<Employee> lstemployees =employeeservice.getallemployees ();  for(Employee employee:lstemployees) {if(Employee.getname (). Equals (name)) {result=false;  Break; }} Map<string, boolean> map =NewHashmap<>(); Map.put ("Valid", result); Objectmapper Mapper=NewObjectmapper (); String resultstring= ""; Try{resultstring=mapper.writevalueasstring (map); } Catch(jsonprocessingexception e) {e.printstacktrace (); }        returnresultstring; }

It is important to note that the bootstrap remote validator needs to return the result must be in JSON format data :

{"Valid":false// indicates illegal, validation does not pass {"valid":true// means valid, validation passed

If any other value is returned, the page validation will not get the validation result resulting in an inability to validate.

Remote verification experience with Bootstrapvalidator

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.