1 var xmlhttp;
2 function ckrname() {
3 var rolename = document.getElementById("rolename").value;
4 var oldRoleName = document.getElementById("oldRoleName").value;
5 if (rolename==""||rolename==null||reg.test(rolename)) {
6 document.getElementById("sprname").style.color="red";
7 document.getElementById("sprname").innerHTML="角色名不能为空";
8 return false;
9 }else{
10 xmlhttp = new XMLHttpRequest();
11 //绑定回调函数状态码改变事件
12 xmlhttp.onreadystatechange=resp;
13 //发送请求准备
14 xmlhttp.open("get", "<%=basePath%>RoleServlet?method=neweditrole&roleName="+rolename+"&oldRoleName="+oldRoleName, true);
15 xmlhttp.send(null);
16 return flag;
17 }
18 }
19 var flag;
20 function resp(){
21 if(xmlhttp.readyState==4&&xmlhttp.status==200){
22 var txt = xmlhttp.responseText;
23 if(txt>0){
24 //alert("用户名已存在,请重新输入!");
25 document.getElementById("sprname").style.color="red";
26 document.getElementById("sprname").innerHTML="角色名已存在,请重新输入!";
27 flag=false;
28 }else{
29 document.getElementById("sprname").innerHTML = "√";
30 document.getElementById("sprname").style.color = "green";
31 flag=true;
32 }
33 }
34 }