Here is an example of editing a validation role name:
First, define a flag global variable.
Then, in the callback function resp (), set the value of flag to true or false in the judgment.
Finally, in the Call Function Ckrname (), return flag is OK.
The code is as follows:
1 varXMLHTTP;2 functionCkrname () {3 varRoleName = document.getElementById ("RoleName"). Value; 4 varOldrolename = document.getElementById ("Oldrolename"). Value; 5 if(rolename== "" | | rolename==NULL||reg.test (rolename)) {6document.getElementById ("Sprname"). style.color= "Red";7document.getElementById ("Sprname"). innerhtml= "role name cannot be empty";8 return false;9}Else{TenXMLHTTP =NewXMLHttpRequest (); One //Binding callback function status code change event AXmlhttp.onreadystatechange=resp; - //Send Request Preparation -Xmlhttp.open ("Get", "<%=basepath%>roleservlet?method=neweditrole&rolename=" +rolename+ "& Oldrolename= "+oldrolename,true); theXmlhttp.send (NULL); - returnFlag; - } - } + varFlag; - functionresp () { + if(xmlhttp.readystate==4&&xmlhttp.status==200){ A varTXT =Xmlhttp.responsetext; at if(txt>0){ - //alert ("Username already exists, please re-enter!") "); -document.getElementById ("Sprname"). style.color= "Red"; -document.getElementById ("Sprname"). innerhtml= "role name already exists, please re-enter! "; -flag=false; -}Else{ indocument.getElementById ("Sprname"). InnerHTML = "√"; -document.getElementById ("Sprname"). Style.color = "Green"; toflag=true; + } - } the}
Solve the Ajax callback function no return is worth the problem