AJAX
  Home arrow AJAX arrow Page 3 - Using the jQuery Framework with 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? 
Google.com  
AJAX

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


    Table of Contents:
  • Using the jQuery Framework with Google`s Ajax Libraries API
  • Review: downloading a JavaScript library via the Google API
  • Working with the jQuery library
  • Serving jQuery’s source file via Google's 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 the jQuery Framework with Google`s Ajax Libraries API - Working with the jQuery library
    ( Page 3 of 4 )

    If you grasped how to use Google's API for downloading the Prototype library directly from the search engine's servers, then it’s probable that you’ll find even simpler to utilize the API in question for working with the jQuery framework.

    The reason for this is simple: regardless of the library being used, the procedure remains practically the same --- first, use the “google.load()” method for downloading a specific package, and then the “google.setOnLoadCallback()” method is responsible for calling a concrete JavaScript function after the complete web page has been loaded.

    You will undoubtedly understand this process better if I provide you with a practical example that shows in detail how to use the API for working with the jQuery library. With that idea in mind, below I rebuilt the Ajax-driven application that you learned in the previous section by using the a local copy of jQuery.

    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 jQuery library</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 language="javascript" src="jquery.js"></script>

    <script>

    $(document).ready(function(){

    $("#btn").click(function(){

    $.get("read_file.php",function(fileContents){$("#filecontents").html(fileContents);});

    });

    });

    </script>

    </head>

    <body>

    <h1 id="header">Reading file contents with jQuery library</h1>

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

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

    </body>

    </html>


    As I explained a few lines before, the above code sample illustrates how to use the jQuery library to recreate the same file reading Ajax application developed in the preceding section. In simple words, this program is responsible for fetching the contents of a text file, via an Ajax HTTP request, to be displayed later within a selected DIV of the web document.

    The PHP script that reads this data from the targeted file is as follows:

    <?php

    if(!$contents=file_get_contents('data.txt')){

    trigger_error('Error reading file contents',E_USER_ERROR);

    }

    echo $contents;

    ?>


    Now that I have listed the PHP scripts that fetch the contents from a text file, called “data.txt,” I will show you how this sample file looks:

    These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file.

    Now that you hopefully understand how each module that comprises this Ajax program works, here’s an additional screen capture that shows the output generated by the application. Take a look, please:



    That was pretty simple to accomplish, right? At this point, I have explained how to build, with the jQuery library, a primitive Ajax application that fetches the content from a selected text file, and then displays it on a screen. Of course, as you saw earlier, this particular example uses a local copy of the library, meaning that it’s time to see how the same program can be rebuilt, this time utilizing Google's API.

    This process will be discussed in detail in the last section of this article. So please read the next segment.



     
     
    >>> 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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek