Using AJAX technology to create a blog without refreshing search engine

Source: Internet
Author: User
Tags empty include log query table name version
Ajax| Blog | refresh | search Engine | no refresh

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
Dim Search_word,xml_result,rssearch,sqlsearch
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 sqlsearch,conn,1,1
' 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
xml_result=xml_result& "<result><logid>#</logid><logtitle/></result>"
End IF
xml_result=xml_result& "</blogsearch>"
' Set MIME type to XML document
Response.ContentType = "Application/xml"
' Response.Charset = ' utf-8 '
' Output search results
Response.Write (Xml_result)

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:


<!--to use JavaScript, external link to-->
<script type= "Text/javascript" src= "Ajaxsearch.js" ></script>
<!--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"/>
<!--search button-->
<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>

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.