我在 JavaScript 中有一个函数:
function login() {
user=document.getElementById("user_id").value;
pass=document.getElementById("password").value;
params="user="+user+"&pass="+pass;
url="check_login.php";
if(window.XMLHttpRequest) {
var http=new XMLHttpRequest();
} else {
var http=new ActiveXObject("Microsoft.XMLHTTP");
}
var http=new XMLHttpRequest();
http.onreadystatechange=function(){
if(http.status==200 && http.readyState==4) {
text=http.responseText;
alert(text.status);
}
}
http.open("POST",url,true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.send(params);
return false;
}
服务器端返回的 json 数据如下:
$return=array("status"=>"true","user"=>$user,"fname"=>$fname,"middle_name"=>$middle_name,"lname"=>$lname);
$return=json_encode($return);
echo $return;
现在警报应该使警报为真,但它不起作用,我希望我能让你清楚