时间:2021-07-01 10:21:17 帮助过:7人阅读
贴出你的代码!
你需要在回调函数中有条件的对不同的目标赋值,那就要回传有控制信息
// JavaScript Documentvar xmlHttp;function S_xmlhttprequest(){ if(window.ActivXObject){ xmlHttp=new ActiveXObject('Mcrosoft.XMLHTTP'); }else if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest; } }function php100(){ S_xmlhttprequest(); user=document.myform.user.value; pwd=document.myform.pwd.value; var postStr = 'user='+ user+'&pwd='+pwd; xmlHttp.open('POST','login3.php',true); //定义传输的文件HTTP头信息 xmlHttp.onreadystatechange=byphp; xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); //发送POST数据 xmlHttp.send(postStr); }function byphp(){ var byphp100=xmlHttp.responseText; document.getElementById('userInfo').innerHTML=byphp100; }// JavaScript Document// JavaScript Document
form name="myform" method="post" action=""> 用户名:
密 码:
“用户名”验证返回的信息显示到userinfo那个div中,密码显示到passinfo那个div中;代码应该怎么改?希望详细些,新手谢谢了!
你没有回传啊
var byphp100=xmlHttp.responseText;
document.getElementById('userInfo').innerHTML=byphp100;这不是回传处理了吗?
function byphp(){ var byphp100=xmlHttp.responseText; if(/用户/.test(byphp100)) document.getElementById('userInfo').innerHTML=byphp100; else document.getElementById('passInfo').innerHTML=byphp100;}
index.html
密码
check.php中判断下$_POST['username']和$_POST['pw']
function byphp(){ var byphp100=xmlHttp.responseText; if(/用户/.test(byphp100)) document.getElementById('userInfo').innerHTML=byphp100; else document.getElementById('passInfo').innerHTML=byphp100;}
传json吧
留名! 用jquery不是更好吗