这里的checkName()w为什么不能是我所期待的返回值(true/false),怎么获得chekName()的返回值,在使用ajax的基础上?求高人指点,
刚开始学习使用ajax进行表单验证;遇到这种问题不知道怎么解决?
,表单的内容是这样的,下面是几个主要的验证函数,
<code>function checkName(){ var name=ele.name.value; if(name!= ""){ xmlhttp=new XMLHttpRequest(); url="http://localhost/chkname.php"; xmlhttp.onreadystatechange =function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ var msg = xmlhttp.responseText; if(msg == '1'){ ele.name.className="";//移除class ele.imgs[0].setAttribute("src","img/right.jpg"); //对应图标 ele.imgs[0].style.display = "inline"; //显示 return true; }else{ ele.name.className="borderRed";//移除class ele.imgs[0].setAttribute("src","img/wrong.jpg"); //对应图标 ele.imgs[0].style.display = "inline"; //显示 biaoqian1.innerHTML='<strong class="tips_false">该用户名已存在</strong>'; return false; } } } } xmlhttp.open('POST',url,true); xmlhttp.send(null); } function check(){ //表单提交则验证开始 if(checkName()&&checkPassw2()&&checkEmail()){ alert(" 注册成功"); //注册成功 return true; } else{ alert("请正确的填写完信息!"); return false; } } </code>
回复内容:
这里的checkName()w为什么不能是我所期待的返回值(true/false),怎么获得chekName()的返回值,在使用ajax的基础上?求高人指点,
刚开始学习使用ajax进行表单验证;遇到这种问题不知道怎么解决?
,表单的内容是这样的,下面是几个主要的验证函数,
<code>function checkName(){ var name=ele.name.value; if(name!= ""){ xmlhttp=new XMLHttpRequest(); url="http://localhost/chkname.php"; xmlhttp.onreadystatechange =function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ var msg = xmlhttp.responseText; if(msg == '1'){<p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite> ele.name.className="";//移除class ele.imgs[0].setAttribute("src","img/right.jpg"); //对应图标 ele.imgs[0].style.display = "inline"; //显示 return true; }else{ ele.name.className="borderRed";//移除class ele.imgs[0].setAttribute("src","img/wrong.jpg"); //对应图标 ele.imgs[0].style.display = "inline"; //显示 biaoqian1.innerHTML='<strong class="tips_false">该用户名已存在</strong>'; return false; } } } } xmlhttp.open('POST',url,true); xmlhttp.send(null); } function check(){ //表单提交则验证开始 if(checkName()&&checkPassw2()&&checkEmail()){ alert(" 注册成功"); //注册成功 return true; } else{ alert("请正确的填写完信息!"); return false; } } </code>