http://onlythebestoftheweb.x10.mx/test%20search/searchbeta.html (Попробуйте, например, искать Google). По какой-то причине, когда я начинаю вводить текст, нажмите кнопку "Обновить". Я не имею понятия почему? Что-то не так с моим кодом? Я не могу найти его. Также вы можете проверить код страницы, которую я вам дал ранее. Если вы также можете узнать, почему он открывает страницу на другой вкладке и исправляет ее, это тоже очень полезно. :)
<?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 suggestions" if no hint were found
// or to the correct values
if ($hint=="")
{
$response="No suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
Вы должны запретить событие по умолчанию для элемента формы "form" на странице searchbeta.html. Это то, что я предлагаю вам в js с помощью jQuery lib:
$(function(){
$("form").on("submit",function(e){
e.preventDefault();
});
});
Не забудьте подключить jQuery lib к своей странице