Home  >  Article  >  Backend Development  >  急PHP+Ajax实现用户登录验证有关问题求解

急PHP+Ajax实现用户登录验证有关问题求解

WBOY
WBOYOriginal
2016-06-13 12:47:30622browse

急!!PHP+Ajax实现用户登录验证问题求解?
表单里用户名和密码两个属性,单击按钮触发AJAX函数,这个AJAX函数提取表单中“用户名”和“密码”的值发送到后台程序验证,php写的后台程序,php程序分别对“用户名”和“密码”进行验证,用户名出错给出提示,传回给ajax,显示到

中,同理密码出错,显示到
中,现在用户名和密码能够正确传到PHP程序中,做出正确验证,但是xmlHttp.responseText,如何能实现上面的效果呀?急!!!

------解决方案--------------------
贴出你的代码!

你需要在回调函数中有条件的对不同的目标赋值,那就要回传有控制信息
------解决方案--------------------
 index.html

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



无标题文档





 密码 







ajax.js
var http_request;
function send_request(url,method) {
  http_request = false;
  if(window.XMLHttpRequest) { 
  http_request = new XMLHttpRequest();
  if (http_request.overrideMimeType) {
   http_request.overrideMimeType('text/xml');
  }
  }
  else if (window.ActiveXObject) { 
  try {
   http_request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
   http_request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e) {}
  }
  }
  if (!http_request) {
  window.alert("不能创建XMLHttpRequest对象实例.");
  return false;
  }
  switch(method){
  case 1:http_request.onreadystatechange = chk;break;
    }
  http_request.open("GET", url, true);
  http_request.send(null);
}

function check(){
send_request("check.php?action="+document.getElementById('pw').value,1);


function chk() {
if (http_request.readyState == 4) { 
 if (http_request.status == 200) {
 document.getElementById("user").innerHTML="";
document.getElementById("user").value=http_request.responseText;
    } else {
     alert("您所请求的页面异常。");
    }
   }else {
 document.getElementById("user").innerHTML="正在读取数据中……";
 }
}


check.php


if(存在){
echo"正确";
}else{
echo "不正确";
}
?>


------解决方案--------------------
传json吧
------解决方案--------------------
留名!   用jquery不是更好吗
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn