javascript - 为什么我的即时搜索不起作用?

标签 javascript php html css

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/

相关文章:

javascript - Highcharts:访问轴格式化程序中的系列或轴上下文

javascript - 当我的工具提示悬停时,会触发 jQuery 中的 Mouseout 事件

javascript - 如何在 SIFR 3r436 中使用各种选择器

javascript - 我如何引用一个已经创建的 handson 表来改变它?

php - 使用复选框更新 php/mysql 中的表单条目?

php - 所有子数组元素无重复的组合

html - 从 CSS 而不是 HTML 选择图像

javascript - Jquery 延迟等等

php - 为什么将posted变量打印到html代码中会导致XSS?

php - php 修改默认时区的方法