AJAX
  Home arrow AJAX arrow Ajax Features Needed to Build Active Client Pages
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

Ajax Features Needed to Build Active Client Pages
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2008-10-14


    Table of Contents:
  • Ajax Features Needed to Build Active Client Pages
  • More About the XMLHttpRequest Object
  • The responseText Property
  • Principles of the Ajax Approach

  • 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


    Ajax Features Needed to Build Active Client Pages
    ( Page 1 of 4 )

    This is the second part of my four-part series, Active Client Pages – Ajax Approach. In this part of the series, we continue our discussion of the Ajax features we will need to use with ACP, and then we look at the principles of the Ajax approach.

    The XMLHttpRequest Object

    By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded!

    The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7.

    Ajax Browsers

    The keystone of AJAX is the XMLHttpRequest object. Different browsers use different methods to create the XMLHttpRequest object. Internet Explorer uses an ActiveXObject, while other browsers uses the built-in JavaScript object called XMLHttpRequest.

    All Ajax requests in JavaScript begin by making a call to the XMLHttpRequest constructor function:

    new XMLHttpRequest() //IE7, Firefox, Safari etc;

    new ActiveXObject("Msxml2.XMLHTTP") //newer versions of IE5+;

    new ActiveXObject("Microsoft.XMLHTTP") //older versions of IE5+;

    new XDomainRequest() //IE8+ only. A more "secure", versatile alternative to IE7's XMLHttpRequest() object.

    In IE6 and below, the XMLHttpRequest() is not supported, but instead relies on the proprietary ActiveXObject for Ajax requests. To create this object, and deal with different browsers, we are going to use a "try and catch" statement. This is a typical way to address the problem (the explanation is given below):


    <html>

    <body>

    <script type="text/javascript">function ajaxFunction()

    {

    var xmlHttp;

    try

    {

    // Firefox, Opera 8.0+, Safari

    xmlHttp=new XMLHttpRequest();

    }

    catch (e)

    {

    // Internet Explorer

    try

    {

    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

    }

    catch (e)

    {

    try

    {

    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

    }

    catch (e)

    {

    alert("Your browser does not support AJAX!");

    }

    }

    }

    }

    </script>

    </body>

    </html>


    Explanation

    In this illustration, the function you write that handles Ajax request is called ajaxFunction.

    First we need to create a variable xmlHttp to hold the XMLHttpRequest object in the function.

    Then we try to create the object with XMLHttp=new XMLHttpRequest(). This is for Firefox, Opera, and Safari browsers. If that fails, we try xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"), which is for Internet Explorer 6.0+. If that also fails, we try xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"), which is for Internet Explorer 5.5+.

    If none of the three methods work, the user has a very outdated browser, and he or she will get an alert stating that the browser doesn't support AJAX.

    Note: The browser-specific code above is long and quite complex. However, you can use this code every time you need to create an XMLHttpRequest object. The code above is compatible with all of the popular browsers: Internet Explorer, Opera, Firefox, and Safari.



     
     
    >>> More AJAX Articles          >>> More By Chrysanthus Forcha
     

       

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