onlythebestoftheweb.x10.mx/test search/search.html 代码有什么问题?尝试在其中键入任何内容而不单击 enter。它曾经有效...我不知道第 3 行和第 31 行有什么问题。继承人 links.xml 和 livesearch.php
onlythebestoftheweb.x10.mx/test search/links.xml
onlythebestoftheweb.x10.mx/test search/livesearch.php
PHP代码
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("links.xml");
$x=$xmlDoc->getElementsByTagName('link');
//get the q parameter from URL
$q=$_GET["q"];
//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('title');
$z=$x->item($i)->getElementsByTagName('url');
if ($y->item(0)->nodeType==1)
{
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
最佳答案
您缺少空缺 <link>
links.xml 第 27 行和第 28 行之间的标记。
如果我转到:http://onlythebestoftheweb.x10.mx/test%20search/links.xml,Chrome 会为我提供有用的错误信息
关于javascript - 为什么我的即时搜索不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22547223/