开发者

Show search results without reloading the page

开发者 https://www.devze.com 2023-03-07 22:17 出处:网络
I want to write a 开发者_开发百科simple search engine that shows the results without reloading the page. I read that it\'s possible with the use of hash. I don\'t know that much about web programming.

I want to write a 开发者_开发百科simple search engine that shows the results without reloading the page. I read that it's possible with the use of hash. I don't know that much about web programming. Currently with the help of tutorials I managed to write this:

<form action="search.php" method="GET" class="searchform">
<input id='txtInput' class="searchfield" type="text" name="search"/>
<input id='btnSubmit' class="searchbutton" type=submit name="submit" value="Search">
</form>

in the search.php file, I echo out the search results:

                for($i=0;$i<$len;$i++) 
                {
                    echo "
                    $titles[$i]<br>
                    $descs[$i]<br><br><br>";
                }

How can I change this to show the search results without reloading the page. (Like google).


What you're talking about is the use of AJAX (Asynchronous Javascript and XML) which allows for queries to a server without reloading a page. If you are using a framework like JQuery you can use the Ajax function to achieve this. Try reading examples to see how it works.


If you want to create all of the functionality on your own you will need to create an indexer. An indexer is a program you have to write using your server side technology c#, php etc. which simply makes http requests to all searchable content on your site. and populates a database or xml file with information about those resources such as their last updated date (for sort) or their current link, title etc.

Once you have such dataset to look into you should use ajax to asynchronously look into that dataset.

However Google search api, SiteSearchASP.NET, php sphider and many more already have come up with open source versions of this which if in a hurry you can take advantage of.

0

精彩评论

暂无评论...
验证码 换一张
取 消