Layui’s form verification supports an instance of Ajax to determine if the username is repeated

layui的表单验证支持ajax判断用户名是否重复的实例 In a form, we want to determine if the user name exists before submitting, not supported in Layui . Onblur () Losing the focus event, manually trigger with the button, the form is not beautiful, you can use the FORM form’s verify to verify.

User name

  Note Lay-Verify = "UserName", define verification events in the JS file. 
Form.Verify ({// Whether the username is available Triggered as a verification condition form submit, username: function (value) {var DataS = {username: value}; var message = ''; $ .ajax ({type: "post", URL: XXX (corresponding background method) , async: false, // change to synchronization request contentType: 'Application / JSON; Charset = UTF-8', DATA: JSON.STRINGIFY (DATAS), DATATYPE: 'JSON', SUCCESS: Function (data) {ix (data) ) {} else {message = "Username already exists, please re-enter!"}}}); // Need to pay attention to the need to write the return information outside the Ajax method IF (Message! == ') Return Message;}} )
Method of backed stations:

// Administrator registration verification user name is available @RequestMapping (value = “/ xxx”, method = RequestMethod.POST, consumes = “application / json”) @ResponseBody public boolean toVerifyUsername (@RequestBody Admin admin) {String username = admin.getUsername (); System.out .println (username); // According to the username query administrator (including Status 0 to prevent recovery caused by bug) admin admin1 = adminservice.FindByUserNameno (username); if (admin1 == null) {system.out.println 111); // Returns TRUE is no such username can be registered with Return true;} else {system.out.println (222); returnaf false;}}

The above Layui’s form verification supports that the example of whether the user name is repeated is that Xiaobian shared all the content, I hope I can give you one. Reference, I also hope that you will support TUMI clouds.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment