JavaScript
  Home arrow JavaScript arrow Page 4 - Creating the Front End of a Search Engine ...
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 
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

Creating the Front End of a Search Engine with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2006-11-15

    Table of Contents:
  • Creating the Front End of a Search Engine with AJAX
  • Creating the search engine’s user interface
  • Creating the application’s look and feel
  • Programming the behavioral layer of the application
  • Putting the pieces together

  • 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


    Creating the Front End of a Search Engine with AJAX - Programming the behavioral layer of the application


    (Page 4 of 5 )

    After having defined the respective (X)HTML markup and CSS rules that make up the front-end of this AJAX-driven search engine, the next logical step that I’m going to take rests on creating the JavaScript functions which are tasked with sending HTTP requests in the background to perform the corresponding search, in addition to showing the eventual results in the browser.

    the code listing below shows the two core JavaScript functions responsible for performing all the tasks that I mentioned before. Please examine their respective signatures:

    // 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');            }         }       } }

    If you felt inclined to think that triggering HTTP requests with AJAX, and displaying the corresponding server responses in the client was a hard process to accomplish, then the above code snippet demonstrates the opposite. As you can see, the first function, called “sendHttpRequest(),” is responsible for sending the search term inputted into the respective search box to the server. The second function simply displays the potential search results to the browser. I told you that all these tasks were easy to perform!

    Okay, I guess that the two previously-defined functions are very easy to grasp, thus if you take some time to recapitulate the things learned until now, you’ll realize that both the presentational and behavioral layers of this search engine have been appropriately created.

    Therefore, I suggest you go ahead and read the last section of this article to see the full client-side code that comprises the application.

    More JavaScript Articles
    More By Alejandro Gervasio


       · Over the course of this first article, you'll learn how to create the user interface...
       · Sir/Madam,This is really one of the best articles i have read in the...
       · Thank you for the kind words on my AJAX article, and I’m glad to know it’s been...
     

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek