JavaScript
  Home arrow JavaScript arrow Page 2 - Building the Server-side Component of a Se...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Building the Server-side Component of a Search Engine with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2006-11-21

    Table of Contents:
  • Building the Server-side Component of a Search Engine with AJAX
  • The search engine's client module
  • Coding the search engine's server module
  • Putting the search engine to work

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building the Server-side Component of a Search Engine with AJAX - The search engine's client module


    (Page 2 of 4 )

    Naturally, before I start developing the actual core module of this search engine,  I'd like you to take a quick look at its complete client-side code. Doing so, you'll understand much better how all the different components that comprise this application fit together.

    Therefore, I listed the full client-code of this AJAX-based search engine below, ready to copy and paste. Please, have a look at it:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>AJAX-BASED SEARCH ENGINE</title> <script language="javascript"> // send http requests function sendHttpRequest(url,callbackFunc,respXml){ var xmlobj=null;    try{       xmlobj=new XMLHttpRequest(); } catch(e){        try{             xmlobj=new ActiveXObject("Microsoft.XMLHTTP");         }       catch(e){             alert('AJAX is not supported by your browser!');             return false;         } }    xmlobj.onreadystatechange=function(){         if(xmlobj.readyState==4){          if(xmlobj.status==200){                 respXml?eval(callbackFunc+
    '(xmlobj.responseXML)'):eval(callbackFunc+'(xmlobj.responseText)'); }         }     }     // open socket connection     xmlobj.open('GET',url,true);     // send http header     xmlobj.setRequestHeader('Content-Type','text/html; charset=UTF-8');     // send http request     xmlobj.send(null); } // display search results function displayResults(results){ var rescontainer=document.getElementById('resultcontainer');     if(!rescontainer){return};     rescontainer.innerHTML=''; rescontainer.innerHTML=results; } window.onload=function(){     if(document.getElementById&&document.
    getElementsByTagName&&document.createElement){       var searchbutton=document.
    getElementsByTagName('form')[0].elements[1]; if(searchbutton){                 searchbutton.onclick=function(){   sendHttpRequest('search.php?searchterm='+document.
    getElementsByTagName('form')[0].elements[0].value,'displayResults');        }         }       } } </script> <style type="text/css"> body{ margin:0;         padding:0;         background:#fff; } h1{         font:bold 28px Arial, Helvetica, sans-serif;         color:#000;         text-align:center; } h2{         font:bold 12px Arial, Helvetica, sans-serif;         color:#c00; } p{         font:normal 12px Arial, Helvetica, sans-serif;         color:#000; } #searchcontainer{         width:600px;         padding:5px 0 5px 0; margin-left:auto; margin-right:auto; background:#9c9; border:1px solid #000; text-align:center; } #resultcontainer{ width:580px; height:500px; padding:10px; margin-left:auto; margin-right:auto; overflow:auto; background:#eee; border-left:1px solid #000; border-right:1px solid #000; border-bottom:1px solid #000; } #resultcontainer ul,li{ display:block; list-style:none; } #resultcontainer a,#resultcontainer a:visited{ font:bold 12px Arial, Helvetica, sans-serif; text-decoration:underline; color:#039;       } #resultcontainer a:hover,#resultcontainer a:active,
    #resultcontainer a:focus{ color:#c00; } .searchbox{ width:200px; font:normal 12px Arial, Helvetica, sans-serif; color:#000; } .searchbutton{ width:80px; font:bold 12px Arial, Helvetica, sans-serif; color:#000;       } </style> </head> <body> <h1>AJAX-BASED SEARCH ENGINE</h1> <div id="searchcontainer"> <form method="get"> <input type="text" name="searchterm" title="Enter your search term here" class="searchbox" /> <input type="button" name="search" value="Search" class="searchbutton" title="Search Now!" /> </form> </div> <div id="resultcontainer"> </div> </body> </html>

     

    All right, as you can see, the complete client-side of this search application is really easy to grasp, since it doesn't present major problems with reference to its definition. Essentially, the above code listing is comprised of the set of JavaScript functions, which are tasked with performing the search process in the background, as well displaying the corresponding results back in the client. Of course, the remaining client code belongs specifically to the (X)HTML markup of the application, thus I won't bore you with irrelevant explanations about what it does.

    So far, so good. As you might have guessed, developing the complete client module of this AJAX-driven search application is actually a direct process that can be achieved with minor troubles. However, the program in question is still incomplete. I've not demonstrated yet how to create the server module responsible for performing real searches against a selected database and displaying the corresponding results.

    Indeed, it seems that there's hard work ahead of us, right? Well, to speak frankly, it's much simpler than you may think. 

    Want to learn how the server-side module of this application will be developed? Please click the link below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · Over the course of this second tutorial, this AJAX-based search engine is expanded,...
       · hello,The article was very helpful, but i have a problem how i can connect...
       · Hello Jova,Thank you for commenting on my AJAX article, and I'm glad to know it...
     

    JAVASCRIPT ARTICLES

    - More on JavaScript Array Objects
    - Methods of the DOM Location Object
    - The DOM Location Object Properties
    - Handling Remote Files with JavaScript Click ...
    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT