Tuesday, 6 November 2007

A simple search engine in Ajax and Coldfusion

In the previous lesson we have seen how to implement a simple search engine using Ajax and PHP. This is a "variation" for coldfusion lovers :)

Download tutorial


Step 1: main page
Repeat step 1 of previous lesson.

Step 2: Javascript function
Change this code line:

http.open('get', 'in-search.php?name='+searchq+'&nocache = '+nocache);

... with:

http.open('get', 'in-search.cfm?name='+searchq+'&nocache = '+nocache);


Step 3: search into database
Now create a blank .cfm page in-search.cfm and copy and paste this code inside of the page:

<cfquery name="getName" datasource="myDatasource">
SELECT * FROM USER
WHERE name LIKE '%#URL.searchq#%'
</cfquery>
<cfoutput query="getName">
#name#
</cfoutput>


The code is very simple. #URL.searchq# is a Coldfusion URL variable passed from javascript function searchNameq() to coldfusion server. How you can see, the structure is the same of previous post using PHP.

No comments:

Post a Comment