鍍金池/ 問答/PHP  HTML/ 關(guān)于ajax和php調(diào)用的疑問?

關(guān)于ajax和php調(diào)用的疑問?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script>
        function showHint(str)
        {
            var xmlhttp;
            if (str.length==0)
            {
                document.getElementById("txtHint").innerHTML="";
                return;
            }
            if (window.XMLHttpRequest)
            {
                xmlhttp=new XMLHttpRequest();
            }
            else
            {
                // IE6, IE5 瀏覽器執(zhí)行代碼
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","test.php?q="+str,true);
            xmlhttp.send();
        }
    </script>
</head>
<body>
<h3>在輸入框中嘗試輸入字母 a:</h3>
<form action="">
   輸入姓名: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>提示信息: <span id="txtHint"></span></p>
</body>
</html>
<?php
// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Cinderella";
$a[]="Diana";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";
//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
  {
  if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    {
    if ($hint=="")
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint." , ".$a[$i];
      }
    }
 }
}
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>

上面是html,下面是php。圖片是編譯出的問題。圖片描述

回答
編輯回答
怣人
  1. 給看 PHP 文件內(nèi)容,遮起來做什么。
  2. 看請求的時候,不用只看 headers, 有一個 response 可以看到內(nèi)容
2018年1月23日 18:52
編輯回答
柒槿年

給我的感覺是你的PHP沒解析 你PHP環(huán)境安裝了嗎

2018年1月26日 08:07