首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

发送ajax没有反映,没报错什么反映也没有,经常遇到这种情况

2012-07-26 
发送ajax没反映,没报错什么反映也没有,经常遇到这种情况。用户注册界面使用ajax,处理ajax请求的是另一个php

发送ajax没反映,没报错什么反映也没有,经常遇到这种情况。
用户注册界面使用ajax,处理ajax请求的是另一个php.
下面是注册界面的javascript部分:
<script type="text/javascript">
  function checkname(name)
  {
  var value=document.getElementById(name).value;
  var error_tip=name+"_error_tip";
  if(value=="")
  {
  document.getElementById(error_tip).innerHTML="Name cannot be empty";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  else
  {
  var patt1=new RegExp("[0-9]");
  var patt2=new RegExp("[^A-z]");
  var r1=patt1.test(value);
  if(r1)
  {  
  document.getElementById(error_tip).innerHTML="Name can not contain digital";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  var r2=patt2.test(value);  
  if(r2)
  {
  document.getElementById(error_tip).innerHTML="The name can not contain numbers or punctuation marks";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  }
  document.getElementById(error_tip).style.visibility="hidden";
  return true;
  }  
  function checkemail(name)
  {
  var validchar="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-@.";
  var value=document.getElementById(name).value;
  var error_tip=name+"_error_tip";
  var flag1=0;
  var flag2=0;
  if(value=="")
  {  
  document.getElementById(error_tip).innerHTML="Email cannot be empty";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  else
  {
  for(var i=0;i<value.length;i++)
  {
  if(validchar.search(value[i])==-1)
  {
  document.getElementById(error_tip).innerHTML="Please enter a valid email";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  if(value[i]=="@")
  {flag1++;}
  if(value[i]==".")
  {flag2++;}
  }
  if((flag1!=1)||(flag2!=1))
  {
  document.getElementById(error_tip).innerHTML="Please enter a valid email";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  document.getElementById(error_tip).style.visibility="hidden";
  return true;
  }
  }  
  function checkpw(name)
  {
  var value=document.getElementById(name).value;
  var error_tip=name+"_error_tip";
  if(value=="")
  {
  document.getElementById(error_tip).innerHTML="Password cannot be empty";


  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  else
  {
  document.getElementById(error_tip).style.visibility="hidden";
  return true;
  }
  }  
  function checkcpw(name)
  {
  var pw=document.getElementById('pw').value;
  var cpw=document.getElementById('cpw').value;
  var error_tip=name+"_error_tip";
  if(pw==cpw)
  {
  document.getElementById(error_tip).style.visibility="hidden";
  return true;
  }
  else
  {
  document.getElementById(error_tip).value="Two entered passwords do not match";
  document.getElementById(error_tip).style.visibility="visible";
  return false;
  }
  }  
  function getxmlhttp()
  {
  var xmlhttp;
  if(window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
  else if(window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHttp");
  }
  return xmlhttp;
  }
  function getvalue(id)
  {
  if(id=="sub")
  {
  if(document.getElementById(id).checked) return 1;
  else return 0;
  }
  else
  return document.getElementById(id).value;
  }  
  function checkcode()
  {
  var code=document.getElementById("captcha_code").value;
  if(code.length<6) return false;
  else return true;
  }  
  function submitinfo()
  {
  var xmlhttp=getxmlhttp();
  if(checkname('fname')&&checkname('lname')&&checkpw('pw')&&checkemail('email')&&checkcpw('cpw')&&checkcode())
  {
  alert('submitinfo1');
  var info="fname="+getvalue('fname')+ "&lname="+getvalue('lname')+"&pw="+getvalue('pw')+"&email="+getvalue('email')+"&sub="+getvalue('sub')+
  "&captcha_code="+getvalue("captcha_code");
  xmlhttp.open("POST","register_action.php",true);
  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlhttp.send(info);
  alert('submitinfo2');  
  }  
  xmlhttp.onreadystatechange=function()
  {
  if(xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  if(xmlhttp.responseText=="1")
  {document.getElementById("code_result").innerHTML="the code entered was incorrect.";
  document.getElementById("code_result").style.visibility="visible";}  
  if(xmlhttp.responseText=="2")
  {document.getElementById("reg_result").innerHTML="Create user successful.";
  document.getElementById("reg_result").style.visibility="visible";}  
  if(xmlhttp.responseText=="3")


  {document.getElementById("reg_result").innerHTML="Email already exist";
  document.getElementById("reg_result").style.visibility="visible";}  
  if(xmlhttp.responseText=="4")
  {document.getElementById("reg_result").innerHTML="Register success,send email failed";
  document.getElementById("reg_result").style.visibility="visible";}  
  if(xmlhttp.responseText=="5")
  {document.getElementById("reg_result").innerHTML="Register user failed'";
  document.getElementById("reg_result").style.visibility="visible";}  
  }
  }  
  }
</script>


[解决办法]

[解决办法]
确实好多~~~ 用jquery 简单些 清楚些
[解决办法]
先把验证那些注释掉,把ajax请求php调通再说。

多半js某个地方错了阻止整个程序的运行。
[解决办法]
$response="1";
echo $response;
die("Sorry, the code entered was incorrect");




类似这种地方,请在echo语句后面截断,就难上面的代码来说,js获取到底返回数据是:1Sorry, the code entered was incorrect,那么你说能正确吗,如果要返回多个数据项,那么你可以josn一个数组返回,而不能想你上面写的那样
[解决办法]

JScript code
if(checkname('fname')&&checkname('lname')&&checkpw('pw')&&checkemail('email')&&checkcpw('cpw')&&checkcode())
[解决办法]
在ajax的回调方法中,直接 alert php那边反回的值,若php那边有啥报错的,都可以显示错了!

热点排行