現在我努力獲得這個簡單的PHP AJAX請求來工作。簡單的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;
?>
每次我點擊任何我在「項」標籤獲取「不確定」的標籤。有誰能解釋爲什麼它是未定義的嗎?
+1 @akellehe - Danget ...打我給它= P – 2010-08-30 20:36:40
哈哈哈,:)謝謝 – KeatsKelleher 2010-08-30 20:38:12
哇無法相信我錯過了:P,謝謝 – Albinoswordfish 2010-08-30 20:40:50