现在我正在努力让这个简单的 PHP AJAX 请求工作。
<html>
<head>
<script type="text/javascript">
function getSuggestions(type){
if(type == "")
{
document.getElementById("entries").innerHTML="test"
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlHttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
document.getElementById("entries").innerHTML=xmlHttp.response;
}
}
xmlHttp.open("GET","getData.php?status="+type,true);
xmlHttp.send();
}
</script>
</head>
<body>
<div id="A" onclick='getSuggestions("A")'>Click for A</div>
<div id="P" onclick='getSuggestions("P")'>Click for P</div>
<div id="R" onclick='getSuggestions("R")'>Click for R</div>
<div id="entries"></div>
</body>
</html>
下面是getData.php
<?php
$status = $_GET["status"];
echo $status;
?>
每次我点击任何标签时,我都会在“entries”标签中看到“undefined”。谁能解释为什么它是未定义的?
最佳答案
使用 xmlHttp.responseText
关于php - 简单的 PHP,AJAX 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3603986/