Based on the additions and deletions to change search maven + ssm about ajax verify that the user of problems exist

Connect one.

Although the basic completion of the verification features, but there are still some problems, such as:

Although the username is available, but it is not legitimate, this situation can not.

We need to change two things, one is EmployeeController.java

    // Check the user name is available 
    @ResponseBody 
    @RequestMapping ( "/ checkuser" )
     public Msg checkUser (String empName) { 
        String REGx = "(^ [A-zA-Z0-9 _-] {6,16} $) | ( ^ [\ u2E80- \ u9FFF] {2,5}) " ;
         IF (! empName.matches (REGx)) {
             return . Msg.fail () the Add (" va_msg "," user name must be English 6-16 Chinese or 2-5 position " ); 
        } the else {
             Boolean B = employeeService.checkUser (empName);
             IF (B) {
                 return Msg.success (); 
            } the else {
                return . Msg.fail () the Add ( "va_msg", "username is not available" ); 
            } 
        } 
    }

Here we check availability before checking the legality of the user, while the error information is stored in va_msg, the message which the wrong error message which to choose.

In add.js in:

$("#empName_add_input").change(function(){
    //$("#empName_add_input").empty();
    var empName = this.value;
    $.ajax({
        url:"/curd_ssm/checkuser",
        data:"empName=" + empName,
        type:"POST",
        success:function(result){
            if(result.code == 100){
                show_validate_msg("#empName_add_input","success","用户名可用");
                $("#emp_save").attr("ajx-va","success");
            }else{
                show_validate_msg("#empName_add_input","error",result.extend.va_msg);
                $("#emp_save").attr("ajx-va","error");
            }
        }        
    });
});

Get the error message function changed from backstage pass over the data.

at this time:

It returns different error messages depending on the error. 

 

Guess you like

Origin www.cnblogs.com/xiximayou/p/12239926.html