JavaScript
  Home arrow JavaScript arrow Page 3 - Displaying Dynamic Content with Pop Up DIV...
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

Displaying Dynamic Content with Pop Up DIVs with the DOM and AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2007-02-14

    Table of Contents:
  • Displaying Dynamic Content with Pop Up DIVs with the DOM and AJAX
  • The source code of the previous pop-up application
  • Adding the functionality of AJAX to the existing application
  • Completing the application

  • 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


    Displaying Dynamic Content with Pop Up DIVs with the DOM and AJAX - Adding the functionality of AJAX to the existing application


    (Page 3 of 4 )

    As I stated in the section that you just read, the next step involved in making the pop-up DIVs truly dynamic consists of creating two additional JavaScript functions. The first one will be tasked with sending HTTP requests in the background via AJAX, while the second one will be responsible for populating the respective pop-up DIVs with content fetched from the server.

    As you’ll see soon, the functionality provided by these two new functions will allow the mentioned DIVs to display data that comes from a text file located on the web server. Do you see how the application now handles a dynamic feature? I bet you do!

    All right, having explained the useful tasks performed by these functions, you'll want to look at their respective signatures. Here they are:

    // 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 fill pop-up DIVS with server contents
    function displayResults(content){
       var popupdiv=document.getElementById('popup');
       if(!popupdiv){return};
       popupdiv.innerHTML='';
       popupdiv.innerHTML=content;
    }

    As shown above, the first function uses the functionality provided by cross-browser HTTP requester objects to fetch a specific file in the server, while the second one simply receives the corresponding contents and displays them inside a DIV element, identified as “popup.” Pretty simple, isn’t it?

    However, the isolated definitions for these brand new JavaScript functions don’t tell anything about the way they work in the context of the application itself. Therefore it’s necessary to put all the pieces together and demonstrate how any pop-up DIV included in the corresponding web document is now capable of displaying data fetched from the server.

    Want to learn how this will be done? Okay, click on the link that appears below and read the following section. We’re almost finished!

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this last article of the series, you'll learn how to populate the pop-up DIVS...
     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







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