AJAX
  Home arrow AJAX arrow Page 4 - Using Google`s Ajax Libraries API
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
AJAX

Using Google`s Ajax Libraries API
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2009-01-05


    Table of Contents:
  • Using Google`s Ajax Libraries API
  • Building a simple Ajax application using a local copy of the Prototype JavaScript library
  • Using Google’s JavaScript Libraries API
  • Versioning with the Google API

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Using Google`s Ajax Libraries API - Versioning with the Google API
    ( Page 4 of 4 )

    True to form, versioning with the Google API is as simple as specifying which version of a particular JavaScript library should be downloaded when calling the pertinent “load()” method that you saw before.

    To help you understand more clearly how this process works, below I have rewritten the Ajax-driven program that was built in the prior section, which now utilizes the versioning feature, to work specifically with Prototype 1.6. Here’s the corresponding code sample:

    <!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>Reading file contents with Prototype library (uses Google API)</title>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #fff;

    }

    h1{

    font: bold 18pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    #filecontents{

    width: 600px;

    padding: 10px;

    border: 1px solid #999;

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    </style>

    <script src="http://www.google.com/jsapi"></script>

    <script>

    // load Prototype library with Google API

    google.load("prototype", "1.6");

    // read file contents with Ajax

    function readFileContents(){

    // send http request

    var ajaxobj=new Ajax.Request('read_file.php',{method: 'get',onComplete: displayFileContents,onFailure: displayError});

    }

    // display file contents

    function displayFileContents(requestObj){

    $('filecontents').innerHTML=requestObj.responseText;

    }

    // display error message

    function displayError(requestObj){

    $('filecontents').innerHTML='Error reading file contents!';

    }

    // initialize file reading application

    function initializeApplication(){

    // attach click handler to HTML button

    Event.observe('btn','click',readFileContents);

    }

    google.setOnLoadCallback(initializeApplication);

    </script>

    </head>

    <body>

    <h1>Reading File Contents with Prototype library (uses Google API)</h1>

    <p><input type="button" id="btn" value="Read File Now!" /></p>

    <div id="filecontents"></div>

    </body>

    </html>


    See how easy it is to work with a specific version of a JavaScript framework when using the Google API? As you can see, the only requirement of this process is to invoke the “load()” method by specifying the exact version of the library that must be served. That’s all.

    With this concluding example I’ve finished this basic introduction to using Google’s JavaScript Libraries API. As usual, feel free to tweak all of the code samples developed in this article. This will give you a more intimate understanding of how to use this API when building your own client-side web applications.

    Final thoughts

    In this first chapter of the series, I explained how to use Google’s Ajax libraries API to download and work with the Prototype framework, instead of utilizing a local copy of it. It’s quite possible that the Google-based approach may appeal to you, particularly if your web hosting service has a heavy load, and you want to deliver your JavaScript files from Google's servers.

    In the next part of the series, I’ll be discussing how to employ Google’s API for working with the jQuery JavaScript library. This can be helpful if you’re currently using this package for developing your client-side applications.

    Don’t miss the upcoming tutorial!



     
     
    >>> More AJAX Articles          >>> More By Alejandro Gervasio
     

       

    AJAX ARTICLES

    - PHP AJAX Form Validation
    - Completing a User-Defined CSS Website with P...
    - Create a User-Defined CSS Website with PHP
    - Build A Better Twitter Chat Client Than Cham...
    - Using Division Equations to Make Web Forms S...
    - Using Integer Multiplication to Protect Web ...
    - Using Simple Checksums for Web Form Verifica...
    - Protecting Web Forms with AJAX
    - Using Prototip with AJAX
    - Using Prototip
    - Using the google.load() Method with Google`s...
    - How to Handle Ajax Errors
    - Uncompressing Source Files with Google`s AJA...
    - Using the jQuery Framework with Google`s Aja...
    - Using Google`s Ajax Libraries API




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