中,现在用户名和密码能够正确传到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">
无标题文档
<script></script>
用户名:
密码
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不是更好吗