Home arrow JavaScript arrow Page 4 - Using AJAX to Build a Web Site Indexing Application with Prototype
JAVASCRIPT

Using AJAX to Build a Web Site Indexing Application with Prototype


One of the best ways to take advantage of the numerous features that come packaged with the Prototype JavaScript library is by using it for developing a real world application. So, welcome to the second installment of the series "Building a web site indexing application with Prototype." If you’re interested in utilizing this robust package for creating an extensible system that indexes web site data, this series will offer you a straightforward guide on how to do this, with minor hassles.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 5
February 27, 2007
TABLE OF CONTENTS:
  1. · Using AJAX to Build a Web Site Indexing Application with Prototype
  2. · Going backwards: listing the complete source code that corresponds to the application’s user interface
  3. · Submitting and displaying web site data in the background
  4. · Assembling the pieces

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using AJAX to Build a Web Site Indexing Application with Prototype - Assembling the pieces
(Page 4 of 4 )

In accordance with the concepts that I expressed right at the end of the previous section, here is the complete source code that belongs to this web site indexing system, including also the pair of JavaScript functions that were defined before:

<!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>Web Site Indexing System using Prototype</title>
<style type="text/css">

body{
   padding: 0;
   margin: 0;
   background: #fff;
}

h1{
   width: 550px;
   padding: 10px;
   background: #ccf;
   margin-left: auto;
   margin-right: auto;
   margin-bottom: 10px;
   font: bold 22px Arial, Helvetica, sans-serif;
   color: #000;
   text-align: center;
   border: 1px solid #999;
}

#sitecontainer{
   width: 550px;
   height: 400px;
   background: #ccf;
   padding: 10px;
   margin-left: auto;
   margin-right: auto;
   margin-bottom: 10px;
   border: 1px solid #999;
   overflow: auto;
}

#sitecontainer p{
   font: normal 11px Verdana, Arial, Helvetica, sans-serif;
   color: #000;      
}

#sitecontainer a:link,#sitecontainer a:visited{
    font: bold 11px Verdana, Arial, Helvetica, sans-serif;
    color: #00f;
    text-decoration: underline;
}

#sitecontainer a:hover{
    color: #c30;
}

#formcontainer{
    width: 550px;
    height: 300px;
    background: #ccf;
    padding: 10px;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid #999;
}

#formcontainer p{
   text-align: right;
    margin-right: 100px;
    font: bold 11px Verdana, Arial, Helvetica, sans-serif;
    color: #000;
}

.inputbox{
    width: 300px;
    padding: 2px;
    background: #eee;
    font: normal 11px Verdana, Arial, Helvetica, sans-serif;
    color: #000;
    border: 1px solid #999;
}

.submitbox{
    font: normal 11px Verdana, Arial, Helvetica, sans-serif;
    color: #000;
    padding: 2px;
}

textarea{
   width: 300px;
   height: 150px;
   padding: 2px;
   background: #eee;
   font: normal 11px Verdana, Arial, Helvetica, sans-serif;
   color: #000;
   border: 1px solid #999;
}

</style>
<script language="javascript" src="prototype-1.4.0.js"></script>
<script language="javascript">
// add new web site to index
function addWebSite(e){
   var params='url='+$F('url')+'&title='+$F('title')
+'&description='+escape($F('description'));
   var xmlobj=new Ajax.Updater('sitecontainer','handle_site_data.php',{method:
'get',parameters: params});
   // prevent form from submitting
   Event.stop(e);
}
// attach handler to window object
Event.observe(window,'load',initializeIndexer,false);
// initialize indexing application
function initializeIndexer(){
   // attach handler to web site form           
   Event.observe('siteform','submit',addWebSite);
   // display website index when web page is loaded
   var xmlobj=new Ajax.Updater('sitecontainer','handle_site_data.php',{method: 'get'});
}
</script>
</head>
<body>
  <h1>WEB SITE INDEXING SYSTEM</h1>
 
<div id="sitecontainer"></div>
  
<div id="formcontainer">
   
<form id="siteform">
     
<p>Your website's URL: <input type="text" id="url"
value="http://" class="inputbox" title="Enter your site's
URL" /></p>
     
<p>Your website's Title: <input type="text" id="title"
class="inputbox" title="Enter your site's Title" /></p>
     
<p>Enter a short description for your website below (max.
256 chars.)</p><p><textarea id="description" title="Enter a
description for your site"></textarea></p>
     
<p><input type="submit" value="Submit Web Site"
class="submitbox" title="Submit Web Site" /></p>
   
</form>
 
</div>
</body>
</html>

Okay, the code listing shown above should be more than enough to get you started using the Prototype library to develop this expansible web site indexing system. I hope you enjoy utilizing this powerful package as much I did.

Final thoughts

In this second article of the series, you finally learned how to use the robust AJAX capabilities that come bundled with Prototype to provide the web site indexing system with the ability to add new web sites to a database table and display existing data.

However, this series isn't finished yet. In the last part I’ll show you how to create a simple PHP script which will take care of interacting with MySQL, as well as send back to the client the corresponding server responses in (X)HTML format.

You’ve been warned, so don’t miss the last tutorial!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials