Now the blog is very popular, I believe that the Internet should be a little longer time friends will be here or there is a blog. For some friends who have some abilities, they may prefer to download a blog program to set up their own blog instead of using the services provided by some blog sites. And most of the blog program with the search function is to submit query keywords to the search page, and then generate search results in the background, and then presented to the user, the process of wasting some bandwidth, such as the sidebar of the blog. To conserve this bandwidth, we can use Ajax to build our own, no refresh log search.
In this tutorial, the table name and Log view page for the database is l-blog, because my blog program is modified from L-blog.
The examples in this tutorial have been tested in real life and can be used directly in L-blog or FBS. Of course, to really use the words still need to do some beautification and perfect.
The log content datasheet in the database is named Blog_content, where the log ID is log_id, the log title is Log_title, the Log View page is blogview.asp, and the parameter is log logid. With this information, you can start creating an XML document template for your search results. When you display search results, you need to display the title of the journal and the ID of the log to create a link to the view log.
Search Results Template Sample.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<!--every reslut is a search result-->
ID of the <!--log-->
< title of the!--log-->
<logtitle>ajax First Experience Hand </logtitle>
Each result is a search results, and in order to handle situations where the relevant content is not found, I define logid as # when the search results are empty.
After you complete the XML document template, you can use ASP to dynamically generate the XML documents needed for your search results. Search keywords are delivered by post.
Search Results Output ajaxsearch.asp
<!--#include file= "commond.asp"-->
<!--#include file= "include/function.asp"-->
' Commond.asp connect files to the database
' There are functions to be used in the function.asp checkstr
Set rssearch=server.createobject ("ADODB. RecordSet ")
' Get search Keywords
Search_word=checkstr (Trim (Request.Form ("Searchword"))
' XML Document Header
xml_result= "<?xml version=" "1.0" "encoding=" "Utf-8" "?><blogsearch>"
IF Search_word<>empty Then
' Create a query SQL statement
Sqlsearch= "Select Log_id,log_title,log_content from Blog_content WHERE log_title like '%" &Search_Word& "%" Log_isshow=true ORDER by log_id DESC "
' Open recordset
' If no search results produce a result, Logid is #, indicating no search results
IF Rssearch.bof and rssearch.eof Then xml_result=xml_result& "<result><logid>#</logid>< Logtitle/></result> "
' Loop output search results
Do as not rssearch.eof
' Loop output every result
xml_result=xml_result& "<result><logid>" &rssearch ("log_id") & "</logid><logtitle ><! [cdata["&rssearch" ("Log_title") & "]]></logtitle></result>"
' keyword is empty, no search results are returned
' Set MIME type to XML document
Response.ContentType = "Application/xml"
' Response.Charset = ' utf-8 '
' Output search results
With the output of the background search results, you can start writing the part of the foreground search.
The first need is to give users input search keywords and display search results where, I use DIV to display these two parts:
<!--user Input part-->
<!--the KeyDown event to process input because it is not using form. Search for--> After the user presses the carriage return
<input type= "text" id= "Searchword"/>
<input type= "button" value= "Search"/>
<!--search results show part-->
<div id= "Search_result" >
< prompts the user to enter the search keyword--> at the beginning of the!--
<ul><li> Please enter the keyword </li></ul>