• I had an interesting  discussion on the phone today with Yoram Meriaz, CEO of MB Technologies, and maker of the remarkable Bindows Ajax framework.  As Ajax becomes more mainstream, organizations have become increasingly interested in taking advantage of rich, interactive, zero-footprint Web-based applications.  As most of you know, Ajax requires no special plug-ins, administrator rights, software installation, or practically anything other than the URL of where it comes from.  And as I've been tracking the products in this space, Bindows has repeatedly bubbled up to the top of the list.

    The first thing that attracted me to Bindows was the crisp feel of the resulting software.  The detail and complexity of the user experiences that Bindows creates is amazing, all without sacrjficing clarity of the interface.  To see why I mean, try this
    Bindows demo application out, which combines a kaleidoscope of controls and windows but operates cleanly and clearly nonetheless.


    Bindows: Ajax Framework Extraordinaire


    I asked Yoram to explain the genesis of Bindows, since they were doing Ajax before Ajax was even a term.  He explained that they were working with the U.S. Air Force Technology Center and they were looking for a way to deploy applications that were just like native programs, but without installation, plug-ins, and were completely self-contained and put nothing on the client.  The result ended up becoming Bindows. 

    Yoram also explained that most customers now using the product are enterprises that want to deploy Web-facing applications and so the features have evolved to support that world.  Bindows includes a raft of enterprise features including a full SOAP-stack, robust extensibility mechanisms, and even a compiler and linker to create the most compact JavaScript code possible.  There is even a forthcoming Eclipse plug-in that will allow developers to use the leading open source IDE.

    With major software vendors like TIBCO and Microsoft planning to vigorously compete in the Ajax framework space, Bindows has its work cut out for it. But my experience so far has shown that they offer one of the slickest products so far.  If you're looking to do Enterprise Web 2.0, Bindows is tough to beat and here today, though the pricing clearly shows they know they have the goods, at $695 per developer seat. You can however use the evaluation version to do full development.

    To make it especially attractive to corporate and government software development, Bindows also has accessibility features, object-oriented constructs designed to resonate with sophisticated software developers, full SSL support for security, and much more.  The current version of Bindows is 1.5 and a new beta 2.0 version is currently available.  I don't often devote full blog posts to a single product but Bindows is worth it and I'm seriously considering it for my own Ajax software development work.

    As Ajax applications become the most popular face of Web 2.0 and the majority of online software becomes powered by Ajax techniques, expect that there will be plenty of business to go around (the
    Ajax patent brouhaha notwithstanding.) I do expect Bindows will be acquired soon enough, with my best guess being Google given that Yahoo now has an impressive new Ajax library of its very own.

    The downside?  I would really like it if the Ajax tool creators would make it easier to create Web 2.0 features like tagging and folksonomies, prefabricated two-way content editing components, rich mashup support tools, smaller reusable pieces, etc.
  • 2005-12-15

    CSS FOR BAR GRAPHS

    Having a working knowledge of XHTML and CSS when developing applications is a big help in knowing what can be done client-side and what should be generated server-side.

    Recently we've had to tackle some interesting visualizations which we coded in XHTML and CSS. The method we used, while fairly simple, was a big help to the engineer and created a very flexible and inexpensive solution. We thought we would share our solution and code in case anyone else ran against similar situations.

    Update

    I posted a live example page with everything in tact. So far I've only been able to test in Firefox 1.0.7, Firefox 1.5, IE 6, Safari 1.3.3, and Opera 9(TP1). You can view it here.

    Basic CSS Bar Graph

    This is a simple bar graph we developed for a tool we're releasing shortly for our client. The concept is simple, utilize the percentage width abilities of CSS to accurately portray a percentage bar graph.

    <style>
        .graph { 
            position: relative; /* IE is dumb */
            width: 200px; 
            border: 1px solid #B1D632; 
            padding: 2px; 
        }
        .graph .bar { 
            display: block;
            position: relative;
            background: #B1D632; 
            text-align: center; 
            color: #333; 
            height: 2em; 
            line-height: 2em;            
        }
        .graph .bar span { position: absolute; left: 1em; }
    </style>
    <div class="graph">
        <strong class="bar" style="width: 24%;">24%</strong>
    </div>
    

    Complex CSS Bar Graph

    This is a more complex visualization, yet still following the same basic idea. Here the graph is a ‘bad’ to ‘good’ indicator with a marker that travels the length of the color scheme. A lighter bar shade also helps indicate the marker position as it travels from left to right.

    <style>
        dl { 
            margin: 0; 
            padding: 0;     				
        }
        dt { 
            position: relative; /* IE is dumb */
            clear: both;
            display: block; 
            float: left; 
            width: 104px; 
            height: 20px; 
            line-height: 20px;
            margin-right: 17px;              
            font-size: .75em; 
            text-align: right; 
        }
        dd { 
            position: relative; /* IE is dumb */
            display: block;     			
            float: left;     
            width: 197px; 
            height: 20px; 
            margin: 0 0 15px; 
            background: url("g_colorbar.jpg"); 
         }
         * html dd { float: none; } 
        /* IE is dumb; Quick IE hack, apply favorite filter methods for 
        wider browser compatibility */
    
         dd div { 
            position: relative; 
            background: url("g_colorbar2.jpg"); 
            height: 20px; 
            width: 75%; 
            text-align:right; 
         }
         dd div strong { 
            position: absolute; 
            right: -5px; 
            top: -2px; 
            display: block; 
            background: url("g_marker.gif"); 
            height: 24px; 
            width: 9px; 
            text-align: left;
            text-indent: -9999px; 
            overflow: hidden;
         }
    </style>
    <dl>
        <dt>Love Life</dt>
        <dd>
            <div style="width:25%;"><strong>25%</strong></div>
        </dd>
        <dt>Education</dt>
        <dd>
            <div style="width:55%;"><strong>55%</strong></div>
        </dd>
        <dt>War Craft 3 Rank</dt>
        <dd>
            <div style="width:75%;"><strong>75%</strong></div>
        </dd>
    </dl>
    

    Vertical CSS Bar Graph

    In this third example, we utilize the same principle vertically and reproduce it multiple times to create a more complex graph. This particular solution was a relief the to client and engineer as all they had to do was calculate percentages, and the look of the graph was much better than their stock graphing component.

    <style>
        #vertgraph {    				
            width: 378px; 
            height: 207px; 
            position: relative; 
            background: url("g_backbar.gif") no-repeat; 
        }
        #vertgraph ul { 
            width: 378px; 
            height: 207px; 
            margin: 0; 
            padding: 0; 
        }
        #vertgraph ul li {  
            position: absolute; 
            width: 28px; 
            height: 160px; 
            bottom: 34px; 
            padding: 0 !important; 
            margin: 0 !important; 
            background: url("g_colorbar3.jpg") no-repeat !important;
            text-align: center; 
            font-weight: bold; 
            color: white; 
            line-height: 2.5em;
        }
    
        #vertgraph li.critical { left: 24px; background-position: 0px bottom !important; }
        #vertgraph li.high { left: 101px; background-position: -28px bottom !important; }
        #vertgraph li.medium { left: 176px; background-position: -56px bottom !important; }
        #vertgraph li.low { left: 251px; background-position: -84px bottom !important; }
        #vertgraph li.info { left: 327px; background-position: -112px bottom !important; }
    </style>
    <div id="vertgraph">
        <ul>
            <li class="critical" style="height: 150px;">22</li>
            <li class="high" style="height: 80px;">7</li>
            <li class="medium" style="height: 50px;">3</li>
            <li class="low" style="height: 90px;">8</li>
            <li class="info" style="height: 40px;">2</li>
        </ul>
    </div>
    

    We hope you enjoyed our examples and find new uses and variations for the concept. Drop us a line if you have any other interesting visualizations using XHTML and CSS and we'll post them here.

  • Ajax, which consists of HTML, JavaScript™ technology, DHTML, and DOM, is an outstanding approach that helps you transform clunky Web interfaces into interactive Ajax applications. The author, an Ajax expert, demonstrates how these technologies work together -- from an overview to a detailed look -- to make extremely efficient Web development an easy reality. He also unveils the central concepts of Ajax, including the XMLHttpRequest object.

    Five years ago, if you didn't know XML, you were the ugly duckling whom nobody talked to. Eighteen months ago, Ruby came into the limelight and programmers who didn't know what was going on with Ruby weren't welcome at the water cooler. Today, if you want to get into the latest technology rage, Ajax is where it's at.

    However, Ajax is far more than just a fad; it's a powerful approach to building Web sites and it's not nearly as hard to learn as an entire new language.

    Before I dig into what Ajax is, though, let's spend just a few moments understanding what Ajax does. When you write an application today, you have two basic choices:

    • Desktop applications
    • Web applications

    These are both familiar; desktop applications usually come on a CD (or sometimes are downloaded from a Web site) and install completely on your computer. They might use the Internet to download updates, but the code that runs these applications resides on your desktop. Web applications -- and there's no surprise here -- run on a Web server somewhere and you access the application with your Web browser.

    More important than where the code for these applications runs, though, is how the applications behave and how you interact with them. Desktop applications are usually pretty fast (they're running on your computer; you're not waiting on an Internet connection), have great user interfaces (usually interacting with your operating system), and are incredibly dynamic. You can click, point, type, pull up menus and sub-menus, and cruise around, with almost no waiting around.

    On the other hand, Web applications are usually up-to-the-second current and they provide services you could never get on your desktop (think about Amazon.com and eBay). However, with the power of the Web comes waiting -- waiting for a server to respond, waiting for a screen to refresh, waiting for a request to come back and generate a new page.

    Obviously this is a bit of an oversimplification, but you get the basic idea. As you might already be suspecting, Ajax attempts to bridge the gap between the functionality and interactivity of a desktop application and the always-updated Web application. You can use dynamic user interfaces and fancier controls like you'd find on a desktop application, but it's available to you on a Web application.

    So what are you waiting for? Start looking at Ajax and how to turn your clunky Web interfaces into responsive Ajax applications.

    Old technology, new tricks

    When it comes to Ajax, the reality is that it involves a lot of technologies -- to get beyond the basics, you need to drill down into several different technologies (which is why I'll spend the first several articles in this series breaking apart each one of them). The good news is that you might already know a decent bit about many of these technologies -- better yet, most of these individual technologies are easy to learn -- certainly not as difficult as an entire programming language like Java or Ruby.

    Ajax defined

    By the way, Ajax is shorthand for Asynchronous JavaScript and XML (and DHTML, and so on). The phrase was coined by Jesse James Garrett of Adaptive Path (see the Resources section) and is, according to Jesse, not meant to be an acronym.

    Here are the basic technologies involved in Ajax applications:

    • HTML is used to build Web forms and identify fields for use in the rest of your application.
    • JavaScript code is the core code running Ajax applications and it helps facilitate communication with server applications.
    • DHTML, or Dynamic HTML, helps you update your forms dynamically. You'll use div, span, and other dynamic HTML elements to mark up your HTML.
    • DOM, the Document Object Model, will be used (through JavaScript code) to work with both the structure of your HTML and (in some cases) XML returned from the server.

    Let's break these down and get a better idea of what each does. I'll delve into each of these more in future articles; for now focus on becoming familiar with these components and technologies. The more familiar you are with this code, the easier it will be to move from casual knowledge about these technologies to mastering each (and really blowing the doors off of your Web application development).

    The XMLHttpRequest object

    The first object you want to understand is probably the one that's newest to you; it's called XMLHttpRequest. This is a JavaScript object and is created as simply as shown in Listing 1.


    Listing 1. Create a new XMLHttpRequest object
    
    
    <script language="javascript" type="text/javascript">
    var xmlHttp = new XMLHttpRequest();
    </script>
    

    I'll talk more about this object in the next article, but for now realize that this is the object that handles all your server communication. Before you go forward, stop and think about that -- it's the JavaScript technology through the XMLHttpRequest object that talks to the server. That's not the normal application flow and it's where Ajax gets much of its magic.

    In a normal Web application, users fill out form fields and click a Submit button. Then, the entire form is sent to the server, the server passes on processing to a script (usually PHP or Java or maybe a CGI process or something similar), and when the script is done, it sends back a completely new page. That page might be HTML with a new form with some data filled in or it might be a confirmation or perhaps a page with certain options selected based on data entered in the original form. Of course, while the script or program on the server is processing and returning a new form, users have to wait. Their screen will go blank and then be redrawn as data comes back from the server. This is where low interactivity comes into play -- users don't get instant feedback and they certainly don't feel like they're working on a desktop application.

    Ajax essentially puts JavaScript technology and the XMLHttpRequest object between your Web form and the server. When users fill out forms, that data is sent to some JavaScript code and not directly to the server. Instead, the JavaScript code grabs the form data and sends a request to the server. While this is happening, the form on the users screen doesn't flash, blink, disappear, or stall. In other words, the JavaScript code sends the request behind the scenes; the user doesn't even realize that the request is being made. Even better, the request is sent asynchronously, which means that your JavaScript code (and the user) doesn't wait around on the server to respond. So users can continue entering data, scrolling around, and using the application.

    Then, the server sends data back to your JavaScript code (still standing in for the Web form) which decides what to do with that data. It can update form fields on the fly, giving that immediate feeling to your application -- users are getting new data without their form being submitted or refreshed. The JavaScript code could even get the data, perform some calculations, and send another request, all without user intervention! This is the power of XMLHttpRequest. It can talk back and forth with a server all it wants, without the user ever knowing about what's really going on. The result is a dynamic, responsive, highly-interactive experience like a desktop application, but with all the power of the Internet behind it.

    Adding in some JavaScript

    Once you get a handle on XMLHttpRequest, the rest of your JavaScript code turns out to be pretty mundane. In fact, you'll use JavaScript code for just a few basic tasks:

    • Get form data: JavaScript code makes it simple to pull data out of your HTML form and send it to the server.
    • Change values on the form: It's also simple to update a form, from setting field values to replacing images on the fly.
    • Parse HTML and XML: You'll use JavaScript code to manipulate the DOM (see the next section) and to work with the structure of your HTML form and any XML data that the server returns.

    For those first two items, you want to be very familiar with the getElementById() method as shown in Listing 2.


    Listing 2. Grab and set field values with JavaScript code
    
    
    // Get the value of the "phone" field and stuff it in a variable called phone
    var phone = document.getElementById("phone").value;
    
    // Set some values on a form using an array called response
    document.getElementById("order").value = response[0];
    document.getElementById("address").value = response[1];
    

    There's nothing particularly remarkable here and that's good! You should start to realize that there's nothing tremendously complicated about this. Once you master XMLHttpRequest, much of the rest of your Ajax application will be simple JavaScript code like that shown in Listing 2, mixed in with a bit of clever HTML. Then, every once in a while, there's a little DOM work...so let's look at that.

    Finishing off with the DOM

    Last but not least, there's the DOM, the Document Object Model. For some of you, hearing about the DOM is going to be a little intimidating -- it's not often used by HTML designers and is even somewhat unusual for JavaScript coders unless you're really into some high-end programming tasks. Where you will find the DOM in use a lot is in heavy-duty Java and C/C++ programs; in fact, that's probably where the DOM got a bit of its reputation for being difficult or hard to learn.

    Fortunately, using the DOM in JavaScript technology is easy, and is mostly intuitive. At this point, I'd normally show you how to use the DOM or at least give you a few code examples, but even that would be misleading. You see, you can get pretty far into Ajax without having to mess with the DOM and that's the path I'm going to show you. I'll come back to the DOM in a future article, but for now, just know that it's out there. When you start to send XML back and forth between your JavaScript code and the server and really change the HTML form, you'll dig back into DOM. For now, it's easy to get some effective Ajax going without it, so put this on the back-burner for now.



    Back to top


    Getting a Request object

    With a basic overview under your belt, you're ready to look at a few specifics. Since XMLHttpRequest is central to Ajax applications -- and probably new to many of you -- I'll start there. As you saw in Listing 1, it should be pretty easy to create this object and use it, right? Wait a minute.

    Remember those pesky browser wars from a few years back and how nothing worked the same across browsers? Well, believe it or not, those wars are still going on albeit on a much smaller scale. And, surprise: XMLHttpRequest is one of the victims of this war. So you'll need to do a few different things to get an XMLHttpRequest object going. I'll take your through it step by step.

    Working with Microsoft browsers

    Microsoft's browser, Internet Explorer, uses the MSXML parser for handling XML (you can find out more about MSXML in Resources). So when you write Ajax applications that need to work on Internet Explorer, you need to create the object in a particular way.

    However, it's not that easy. MSXML actually has two different versions floating around depending on the version of JavaScript technology installed in Internet Explorer, so you've got to write code that handles both cases. Look at Listing 3 for the code that you need to create an XMLHttpRequest on Microsoft browsers.


    Listing 3. Create an XMLHttpRequest object on Microsoft browsers
    
    
    var xmlHttp = false;
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    

    All of this won't make exact sense yet, but that's OK. You'll dig into JavaScript programming, error handling, conditional compilation, and more before this series is finished. For now, you want to get two core lines into your head:

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

    and

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

    In a nutshell, this code tries to create the object using one version of MSXML; if that fails, it then creates the object using the other version. Nice, huh? If neither of these work, the xmlHttp variable is set to false, to tell your code know that something hasn't worked. If that's the case, you've probably got a non-Microsoft browser and need to use different code to do the job.

    Dealing with Mozilla and non-Microsoft browsers

    If Internet Explorer isn't your browser of choice or you write code for non-Microsoft browsers, then you need different code. In fact, this is the really simple line of code you saw back in Listing 1:

    var xmlHttp = new XMLHttpRequest object;.

    This much simpler line creates an XMLHttpRequest object in Mozilla, Firefox, Safari, Opera, and pretty much every other non-Microsoft browser that supports Ajax in any form or fashion.

    Putting it together

    The key is to support all browsers. Who wants to write an application that works just on Internet Explorer or an application that works just on non-Microsoft browsers? Worse yet, do you want to write your application twice? Of course not! So your code combines support for both Internet Explorerand non-Microsoft browsers. Listing 4 shows the code to do just that.


    Listing 4. Create an XMLHttpRequest object the multi-browser way
    
    
    /* Create a new XMLHttpRequest object to talk to the Web server */
    var xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    @end @*/
    
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    

    For now, ignore the commenting and weird tags like @cc_on; those are special JavaScript compiler commands that you'll explore in depth in my next article, which will focus exclusively on XMLHttpRequest. The core of this code breaks down into three steps:

    1. Create a variable, xmlHttp, to reference the XMLHttpRequest object that you will create.
    2. Try and create the object in Microsoft browsers:
      • Try and create the object using the Msxml2.XMLHTTP object.
      • If that fails, try and create the object using the Microsoft.XMLHTTP object.
    3. If xmlHttp still isn't set up, create the object in a non-Microsoft way.

    At the end of this process, xmlHttp should reference a valid XMLHttpRequest object, no matter what browser your users run.

    A word on security

    What about security? Today's browsers offer users the ability to crank their security levels up, to turn off JavaScript technology, and disable any number of options in their browser. In these cases, your code probably won't work under any circumstances. For these situations, you'll have to handle problems gracefully -- that's at least one article in itself, one I will tackle later (it's going to be a long series, isn't it? Don't worry; you'll master all of this before you're through). For now, you're writing robust, but not perfect, code, which is great for getting a handle on Ajax. You'll come back to the finer details.



    Back to top


    Request/Response in an Ajax world

    So you now understand Ajax and have a basic idea about the XMLHttpRequest object and how to create it. If you've read closely, you even realize that it's the JavaScript technology that talks to any Web application on the server rather than your HTML form being submitted to that application directly.

    What's the missing piece? How to actually use XMLHttpRequest. Since this is critical code that you'll use in some form in every Ajax application you write, take a quick tour through what a basic request/response model with Ajax looks like.

    Making a request

    You have your shiny new XMLHttpRequest object; now take it for a spin. First, you need a JavaScript method that your Web page can call (like when a user types in text or selects an option from a menu). Then, you'll follow the same basic outline in almost all of your Ajax applications:

    1. Get whatever data you need from the Web form.
    2. Build the URL to connect to.
    3. Open a connection to the server.
    4. Set up a function for the server to run when it's done.
    5. Send the request.

    Listing 5 is a sample of an Ajax method that does these very things, in this order:


    Listing 5. Make a request with Ajax
    
    
    function callServer() {
      // Get the city and state from the web form
      var city = document.getElementById("city").value;
      var state = document.getElementById("state").value;
      // Only go on if there are values for both fields
      if ((city == null) || (city == "")) return;
      if ((state == null) || (state == "")) return;
    
      // Build the URL to connect to
      var url = "/scripts/getZipCode.php?city=" + escape(city) + "&state=" + escape(state);
    
      // Open a connection to the server
      xmlHttp.open("GET", url, true);
    
      // Setup a function for the server to run when it's done
      xmlHttp.onreadystatechange = updatePage;
    
      // Send the request
      xmlHttp.send(null);
    }
    

    A lot of this is self-explanatory. The first bit of the code uses basic JavaScript code to grab the values of a few form fields. Then the code sets up a PHP script as the destination to connect to. Notice how the URL of the script is specified and then the city and state (from the form) are appended to this using simple GET parameters.

    Next, a connection is opened; here's the first place you see XMLHttpRequest in action again. The method of connection is indicated (GET), as well as the URL to connect to. The final parameter, when set to true, requests an asynchronous connection (thus making this Ajax). If you used false, the code would wait around on the server when the request was made and not continue until a response was received. By setting this to true, your users can still use the form (and even call other JavaScript methods) while the server is processing this request in the background.

    The onreadystatechange property of xmlHttp (remember, that's your instance of the XMLHttpRequest object) allows you to tell the server what to do when it does finish running (which could be in five minutes or five hours). Since the code isn't going to wait around for the server, you'll need to let the server know what to do so you can respond to it. In this case, a specific method -- called updatePage() -- will be triggered when the server is finished processing your request.

    Finally, send() is called with a value of null. Since you've added the data to send to the server (the city and state) in the request URL, you don't need to send anything in the request. So this fires off your request and the server can do what you asked it to do.

    If you don't get anything else out of this, notice how straightforward and simple this is! Other than getting the asynchronous nature of Ajax into your head, this is relatively simple stuff. You'll appreciate how it frees you up to concentrate on cool applications and interfaces rather than complicated HTTP request/response code.

    The code in Listing 5 is about as easy as it gets. The data is simple text and can be included as part of the request URL. GET sends the request rather than the more complicated POST. There's no XML or content headers to add, no data to send in the body of the request -- this is Ajax Utopia, in other words.

    Have no fear; things will become more complicated as this series progresses. You'll learn how to send POST requests, how to set request headers and content types, how to encode XML in your message, how to add security to your request -- the list is pretty long! Don't worry about the hard stuff for now; get your head around the basics, and you'll soon build up a whole arsenal of Ajax tools.

    Handling the response

    Now you need to actually deal with the server's response. You really only need to know two things at this point:

    • Don't do anything until the xmlHttp.readyState property is equal to 4.
    • The server will stuff it's response into the xmlHttp.responseText property.

    The first of these -- ready states -- is going to take up the bulk of the next article; you'll learn more about the stages of an HTTP request than you ever wanted to know. For now, if you simply check for a certain value (4), things will work (and you'll have something to look forward to in the next article). The second item -- using the xmlHttp.responseText property to get the server's response -- is easy. Listing 6 shows an example of a method that the server can call based on the values sent in Listing 5.


    Listing 6. Handle the server's response
    
    
    function updatePage() {
      if (xmlHttp.readyState == 4) {
        var response = xmlHttp.responseText;
        document.getElementById("zipCode").value = response;
      }
    }
    

    Again, this code isn't so difficult or complicated. It waits for the server to call it with the right ready state and then uses the value that the server returns (in this case, the ZIP code for the user-entered city and state) to set the value of another form field. The result is that the zipCode field suddenly appears with the ZIP code -- but the user never had to click a button!. That's the desktop application feel I talked about earlier. Responsiveness, a dynamic feel, and more, all with a little Ajax code.

    Observant readers might notice that the zipCode field is a normal text field. Once the server returns the ZIP code and the updatePage() method sets the value of that field with the city/state ZIP code, users can override the value. That's intentional for two reasons: To keep things in the example simple and to show you that sometimes you want users to be able to override what a server says. Keep both in mind; they're important in good user-interface design.



    Back to top


    Hooking in the Web form

    So what's left? Actually, not much. You have a JavaScript method that grabs information that the user put into a form, sends it to the server, provides another JavaScript method to listen for and handle a response, and even sets the value of a field when that response comes back. All that's really left is to call that first JavaScript method and start the whole process. You could obviously add a button to your HTML form, but that's pretty 2001, don't you think? Take advantage of JavaScript technology like in Listing 7.


    Listing 7. Kick off an Ajax process
    
    
    <form>
     <p>City: <input type="text" name="city" id="city" size="25" 
           onChange="callServer();" /></p>
     <p>State: <input type="text" name="state" id="state" size="25" 
           onChange="callServer();" /></p>
     <p>Zip Code: <input type="text" name="zipCode" id="city" size="5" /></p>
    </form>
    

    If this feels like yet one more piece of fairly routine code, then you're right -- it is! When a user puts in a new value for either the city or state field, the callServer() method fires off and the Ajax fun begins. Starting to feel like you've got a handle on things? Good; that's the idea!



    Back to top


    In conclusion

    At this point, you're probably not ready to go out and write your first Ajax application -- at least, not unless you're willing to do some real digging in the Resources section. However, you can start to get the basic idea of how these applications work and a basic understanding of the XMLHttpRequest object. In the articles to come, you'll learn to master this object, how to handle JavaScript-to-server communication, how to work with HTML forms, and even get a handle on the DOM.

    For now, though, spend some time thinking about just how powerful Ajax applications can be. Imagine a Web form that responds to you not just when you click a button, but when you type into a field, when you select an option from a combo box...even when you drag your mouse around the screen. Think about exactly what asynchronous means; think about JavaScript code running and not waiting on the server to respond to its requests. What sorts of problems can you run into? What areas do you watch out for? And how will the design of your forms change to account for this new approach in programming?

    If you spend some real time with these issues, you'll be better served than just having some code you can cut-and-paste and throw into an application that you really don't understand. In the next article, you'll put these ideas into practice and I'll give you the details on the code you need to really make applications like this work. So, until then, enjoy the possibilities of Ajax.



    Back to top


    Resources

    Learn

    Discuss
  • Year in Review: AJAX Desktops and Homepages
    By Stephen Bryant


    Review: Home pages are making a comeback, thanks to AJAX and Flash-powered "desktop" applications. Inside, a look at seven desktop and homepage apps vying for your news feeds, bookmarks, and sticky notes.


    The homepage is making a comeback. But this time, unlike in the mid-'90s, home pages aren't simply lists of links. And, unlike today's typical start pages—MSN, Yahoo!, aol.com—these "Web 2.0" homepages prioritize personalized content and customizable interfaces and offer a variety of applications normally found on the desktop.

    The new homepage styles range from personal pages with customizable RSS feeds to GUI-based applications that recreate the desktop metaphor online.

    The economics of this space are uncertain, but that hasn't stopped a host of competitors from crowding the field.

    Windows Live

    windows live desktopMicrosoft's live.com is a great example of how a large company can learn from, and even one-up, its more agile competitors. And, judging by live.com's various blogs and their attendant developer photos, Microsoft is very interested in advertising itself as a young, hip company that can move quickly in this space.

    Live.com is the public face of start.com. The latter, launched two months prior in September, is effectively a testing space for live.com features. Those core features, which are standard among most AJAX home pages, include drag-and-drop content modules, customizable column layout, e-mail integration (Hotmail only) and the ability to save searches.

    Live.com also features the ability to build your own features though Microsoft Gadgets. Think personalized gaming score trackers, iTunes or Amazon lists, photo browsers, etc. Gadgets are created with javascript, XML and CSS, and you host them through live.com. See the getting started page for more details.

    Even more features are expected today, including a new instant messenger client embedded into the site that will also allow you to make outbound VOIP calls.

    Google

    googleGoogle IG is a strong and relatively flexible AJAX desktop. The big idea here is to integrate your Gmail account, stock tickers, search history, and local results onto one page.

    Also of use: Google IG provides an "edit" button on each module, which, when clicked, reveals additional options. These options, like the ability to show a greater or lesser number of items or to change your zip code for localized movie results, are beautiful in their simplicity. Once again, Google doesn't succumb to feature glut, unlike some competitors in this space.

    Google might be well-served by integrating an AJAX-y version of Google Talk, and by offering a few more page layout options. Right now, you're confined to three columns.

    Goowy

    goowyOf all the competitors in this space, Goowy goes furthest in replicating the desktop metaphor and experience. It's also the most fully-realized Web-based desktop platform, and for good reason: Goowy was developed by the same entrepreneurs who developed the original portal software behind Geocities.

    Goowy started out in the spring of this year as a Web-based, Flash-based e-mail client, and Goowy's best service is still its e-mail. When you sign up for a page, you automatically get an @goowy.com e-mail address and 2GB of storage space.

    Goowy's GUI (get it?) replicates the Mac aesthetic. Goowy has impressive pre-made widgets, including impressive del.icio.us integration that shows a thumbnail of your saved page. There's a robust gaming interface and contact manager, and several customization options.

    Goowy also offers the usuals—draggable windows, RSS feeds—but curiously absent is the ability to change a window's size. You can't change a window's dimensions by dragging, and you can't change the number of items displayed inside via the edit button.

    Goowy is a great platform for someone looking to recreate much of their desktop online, but probably not good for someone who just needs an RSS reader, bookmarks and search.

    Netvibes

    netvibesNetvibes is an elegant and functional homepage that provides a lot of extensibility without crowding the page with options.

    The standout features here are integration with writely.com and bookmark tags.

    The standards are also here, including RSS feeds and draggable modules. Netvibes offers Gmail, and Flickr integration. The module edit button offers simple but effective options; the choice to open an RSS feed on the homepage or directly on the site is very convenient.

    Netvibes' search module offers Google, Yahoo, IceRocket and Wikipedia searches. Like Google IG, Netvibes constrains you to three columns. The Netvibes blog contains development info.

    Protopage

    Protopage desktopProtopage is an AJAX homepage on steroids. The site offers a wealth of features, but sometimes those features contribute to a crowded space.

    Protopage tries to overcome that problem with two interesting features: multiple pages and full-size windows.

    Like Goowy, Protopage also does away with the grid and lets you drag and drop windows willy-nilly. The development blog mentions that an auto-arrange feature is on the way.

    According to Protopag's managing director, the site does use AJAX technologies, but also makes use of Javascript Object Notation (JSON), a subset of the object literal notation of JavaScript.

    Protopage was a relatively early entrant into this space and does not currently offer integration with e-mail, flickr, or del.icio.us.

    Eskobo

    eskoboThe latest entrant to the Web 2.0 home page field is also the poorest. Granted, the service is still in beta, but Eskobo seems little more than a Windows Live knockoff, and most of its features don't work as advertised.

    With Eskobo you can add RSS feeds and import OPML files, but neither method was working at the time of this writing. There doesn't seem to be a way to organize your personal feeds into the pre-generated categories of feeds.

    It is unclear what engine the search function uses. Regardless, the search function was also broken at the time of this writing. Eskobo did not return e-mails for comment.

    Zoozio

    zoozio desktopZoozio is still in pre-beta, and its home page only demonstrates a few standard features. Stay tuned for more.

    Editor's Note: This story was updated to include additional information from some companies, and to correct an error.

  • Try out these live AJAX powered demos:
    autocompletion live demo shopping cart live demo

    Check out the list of available demos.

    Visual effects

    Web applications don't have to stay behind the current graphical trends in ultra-rich-desktop-applications. And they don't have to resort to fancy plug-ins that break usability and accessibility. Browsers and standards have reached a stage where advanced animations are finally possible to do with JavaScript.

    Visit the visual effects page to learn more. Here's a quick demo to get you started (Hint: try fewer than 3 characters on the search).

    Advanced options

    Drag-and-drop

    Want some more user interaction than the same old INPUT elements and drop-downs? How about drag-and-drop with built-in support for sortable lists, floats and AJAX serializing? Go to the drag-and-drop page for complete coverage.

    mug t-shirt
    Drag all the stuff you ever want right here.

    Controls

    Make your users happier by providing them with local- or AJAX-controlled auto-completing text fields.

    Type a name:


    Downloads

    For downloads and installation instructions, head to the downloads section.

    The scripts you'll find here all make use of the fully object-oriented Prototype JavaScript library, which comes (like script.aculo.us!) with the Ruby on Rails web application development framework. (But you can use Prototype and script.aculo.us with any web development tools, even with static HTML pages!)


  • http://www.aventureforth.com/2005/09/06/top-10-ajax-applications/

    Update (9/16/05): see my followup with more interesting Ajax applications here.
    http://www.aventureforth.com/2005/09/16/top-10-ajax-applications-part-2/


    Ajax
    http://en.wikipedia.org/wiki/Ajax_(programming)
    programming techniques have recently generated lots of buzz for good reason: they can be used to create interesting browser-based applications that do things many thought impossible with typical web browsers (in particular, a certain Ajax technique can send and receive data to and from a server without requiring the browser to refresh or reload).

    Following are my picks for the 10 best Ajax applications. Selection criteria: (1) an appropriate combination of simplicity and rich functionality, (2) somehow compelling (hard to define, but I know it when I see it), (3) the more interactive, the better, and (4) free. Also, in this exercise, I’m focused on startups, so I’m not including anything from Google (maps, Suggest), Microsoft (Kahuna), or Yahoo (Flickr).

    1. Kiko.
    http://www.kiko.com/
    A general purpose online calendar. Elegant interface and design. API coming soon.

    2. Backbase’s RSS Reader.
    http://www.backbase.com/demos/RSS/#aid=901[1]
    Only a demo, so you can’t add your own feeds. Still, very nice.

    3. Backpack.
    http://www.backpackit.com/
    To do list organizer and simple project management application. Includes email and mobile reminders.

    4. Writely.
    http://www.writely.com/
    Online word processor. A bit rough around the edges (you can’t save in MSF T Word format, for example) but still feels like a real application. Update: per Sam Schillace @ Writely, you can export in Word format (ed: sorry for missing this). Also, API and blog publishing features coming soon.

    5. Amazon Zuggest.
    http://www.francisshanahan.com/zuggest.aspx
    Francis Shanahan’s version of Google Suggest–but for Amazon.

    6. TimeTracker.
    http://www.formassembly.com/time-tracker/
    Personal time management tool.

    7. Del.icio.us Director.
    http://johnvey.com/features/deliciousdirector/
    Rich UI for managing your del.icio.us links.

    8. Backbase’s Information Portal.
    http://projects.backbase.com/RUI/portal.html
    A highly interactive aggregation page.

    9. Protopage.
    http://www.protopage.com/
    Another twist on an information portal.

    10. Periodic Table of the Elements.
    http://code.jalenack.com/periodic/
    The next must-have for high school chemistry students?
  • PostPosted: Sun Oct 09, 2005 12:21 am    Post subject: AJAX Powers Web 2.0 GrowthReply with quote

    http://www.publish.com/article2/0,1895,1867584,00.asp

    AJAX Powers Web 2.0 Growth
    By Stephen Bryant
    October 5, 2005

    Reporter's Notebook: JavaScript, once a much-maligned scripting language, is now at the forefront of the Web 2.0 technology evolution. But where's the business model for AJAX-powered applications?






    SAN FRANCISCO—Jesse James Garrett leaned on a stool at the front of the Web 2.0 Conference's AJAX workshop here Wednesday, sipping from a bowler glass and striking a Joycian figure with his goatee and horn-rimmed glasses.

    The man who coined the term AJAX (Asynchronous JavaScript and XML)—"In the shower I think, right, Jesse?" said Peter Merholz, a co-worker at Adaptive Path LLC—agreed with publisher Tim O'Reilly's Web 2.0-as-paradigm-shift argument .

    "The applications 2.0 revolution isn't a technological revolution at all, it's a revolution in our understanding of how to use these technologies better," Garrett said.

    To wit, the panel didn't discuss any revolutionary business models. Instead, they spoke about how the AJAX-powered Web 2.0 revolution (or evolution, if you prefer) is changing existing business models and Web sites for the better.

    Garrett said that Google, for example, "applied these technologies to problems people thought had been solved," such as how best to handle e-mail and maps.

    What got everybody's attention about Google's applications is that the company figured out how to deploy these new technologies without compromising technology.



    The Web 1.0 party line was always, "Sure, we can make this app look cool if the user has Internet Explorer or if they have the right plug-in." Today, that concern has almost been obviated.

    But Garrett and Merholz stressed that collaboration between designers and developers is key. Whereas it was very difficult to hang yourself with HTML alone, today's technologies require greater teamwork to pull off.

    But where's the business case and the ROI (return on investment) with AJAX-powered apps? The panel, which included Joe Chung of Allurent, Inc., Evan Goldberg from NetSuite Inc. and Peter Kaminski of Socialtext Inc., didn't have a clear answer.

    "The business owners … understand the technology now and have become the drivers," Chung said. "But to really understand the ROI, you have to bring in statisticians and do a controlled study. Your hunches aren't good enough anymore."

    Read a roundup here of the current top 10 Web 2.0 apps for the office.

    Chung demonstrated Allurent Inc.'s shopping cart application, which took advantage of Flash to improve upon the typically frustrating online shopping experience.

    Merholz added, "Right now the business case is largely around the experience. It's going to have to get more finalized, and pretty soon, to drive adoption."

    Of course, there are roadblocks to widespread AJAX adoption. One of the largest is the lack of development tools available to AJAX developers.

    "I think the lack of development tools, yeah, that's a roadblock," Garrett said. "But the market opportunity is just too big. I think that if you're in an organization that has a real strong tech culture that goes all the way up to the top level, there's going to be some hesitancy to do anything with JavaScript. They're going to need to be convinced."

    Part of the reason, the panelists agreed, was that JavaScript was much abused, and thus almost universally maligned, after its debut.

    So where does the business opportunity exist right now? Everywhere. AJAX is an evolutionary approach to technology because it allows developers to do redo basically every application on the Web, as Google did with Gmail and Google Maps.

    Click here to read about Google's Weblog search.

    Garrett and Merholz debuted the pre-alpha of their site traffic analyzer, MeasureMap. Interestingly, the application combines AJAX techniques and Flash technology.

    "Flash is definitely one of these technologies that has proven itself," Garrett said. "Flash certainly has better development tools than JavaScript developers have available to them."

    Garrett added that Flash is great at data visualization and direct manipulation of data. What's more, applications like MeasureMap and technologies like sIFR demonstrate that Flash can be used without the presence of a Flash UI. Flash and AJAX can talk to each other, and the user never even has to know.

    The future of AJAX technologies may be influenced, in part, by how organizations accommodate the disparate Flash and JavaScript development cultures.

    Meanwhile, several companies wanting to be part of the Web 2.0 evolution made announcements today.

    Attentiontrust.org announced the Attention Trust Recorder, a Firefox extension that records browsing history and saves it both to your desktop and to the Attention Trust service. You can then choose which parts of that history you want to share with service providers.

    Flock announced that it is expanding its beta group from a few hundred to a few thousand new users today as well. Interested parties can sign up at flock.com.

    And Zevents announced its social event manager/calendar today, just in time to hear Yahoo Inc. announce that it has acquired upcoming.org.

  • http://news.com.com/AJAX+gives+software+a+fresh+look/2100-1007_3-5886709.html

    update An emerging Web development technique promises to shake up the status quo in PC software and blur the line between desktop and Web applications.

    Over the years, desktop applications tied to a specific operating system have become entrenched as the main way to work on a computer. AJAX, a set of development techniques standardized over the past eight years, could change all that by bringing more sophisticated interfaces to Web applications. With that, backers are hoping it can open a crack in the dominance of desktop software like Microsoft's Office, the undisputed market leader.

    "This is a space that's crying out for innovation," said Scott Dietzen, president of messaging start-up Zimbra. "At this point, there isn't a company that's up to challenging Microsoft. But we're out to change that."

    On Tuesday, closely watched Zimbra outlined its business model and announced that it has secured $16 million in venture funding in conjunction with this week's Web 2.0 conference in San Francisco. The San Mateo, Calif.-based company said it will launch its e-mail server software as a free open-source edition next month. Customers can pay a yearly subscription fee for updates and support, and a higher-end version will be available for a price.

    Zimbra is one of a growing number of companies that are betting that AJAX, which stands for Asynchronous JavaScript + XML, will turn out to be more than just a catchy abbreviation. In the development style, programmers use a number of standards-based technologies, notably JavaScript and XML, to write applications. Many Web entrepreneurs and established software providers are hoping that AJAX can reinvigorate the PC software business by marrying the graphical user interface of desktop computers with the benefits of the Web.

    Clearly, nobody expects AJAX-style applications--just now entering the market--to overtake Office anytime soon. Microsoft has long controlled more than 90 percent of the desktop software market, and the company's Information Worker unit, which includes Office and related tools, generated more than $11 billion in revenue--more than one quarter of Microsoft's total revenue in fiscal year 2005, according to the company.

    But companies like Zimbra are paving the way for others to enter a market long thought to be stagnant.

    "My sense is that we're just seeing the tip of the iceberg when it comes to browser-based applications," Dan Grossman, venture capitalist at Venrock Associates wrote in a recent blog posting. "There are many more on the way, and we'll be increasingly amazed with what can be done," he noted.

    Several smaller companies are in the early stages of building AJAX-style applications that are Web-based alternatives to many PC mainstays, potentially luring away Microsoft customers. Examples include project management application Basecamp and an online calendar program now in beta from CalendarHub.

    At the moment, Web pages are limited, compared with most desktop applications. AJAX frees Web pages from the clunkiness they suffer from by making them more interactive and so more functional, Web developers say.

    Using AJAX, developers can create an interactive user interface that's comparable to what's available on desktop applications. For example, Microsoft Outlook users take for granted that they can drag an e-mail message into a folder, but that's not possible right now with Web-based e-mail clients like MSN Hotmail. With Ajax applications, users can move items such as windows and buttons around a Web page--much as they do with programs linked to Windows or Mac OS.

    "Without AJAX, we couldn't have created a user experience that was good enough," said Seth Sternberg, co-founder of Meebo.com , a three-person start-up that provides Web-based instant messaging.

    Smaller software makers such as ThinkFree and Writely could eventually create the hosted Web equivalent of Microsoft Office, analyst and writer Richard MacManus noted recently.

    Mashing up e-mail
    Dietzen said a Web-based architecture provides benefits to IT administrators, namely a common security system and simplified management. Perhaps more significantly, the Web-based architecture lets Zimbra combine e-mail with other applications in novel ways, he said.

    "The big thing is e-mail-based 'mash-ups.' The Web is becoming this platform for collaboration. Why should we isolate e-mail?" Dietzen said.

    Earlier this year, Google Maps, one of the first applications to make the benefits of AJAX development clear to a broad audience, emerged. The program enables people to use a mouse to move a map image around the screen.

    Zimbra programmers have used the same techniques to make e-mail clients and servers more interactive. The company's Web-based client
    At the moment, Web pages are limited, compared with most desktop applications. AJAX frees Web pages from the clunkiness they suffer from by making them more interactive and so more functional, Web developers say.

    Using AJAX, developers can create an interactive user interface that's comparable to what's available on desktop applications. For example, Microsoft Outlook users take for granted that they can drag an e-mail message into a folder, but that's not possible right now with Web-based e-mail clients like MSN Hotmail. With Ajax applications, users can move items such as windows and buttons around a Web page--much as they do with programs linked to Windows or Mac OS.

    "Without AJAX, we couldn't have created a user experience that was good enough," said Seth Sternberg, co-founder of Meebo.com , a three-person start-up that provides Web-based instant messaging.

    Smaller software makers such as ThinkFree and Writely could eventually create the hosted Web equivalent of Microsoft Office, analyst and writer Richard MacManus noted recently.

    Mashing up e-mail
    Dietzen said a Web-based architecture provides benefits to IT administrators, namely a common security system and simplified management. Perhaps more significantly, the Web-based architecture lets Zimbra combine e-mail with other applications in novel ways, he said.

    "The big thing is e-mail-based 'mash-ups.' The Web is becoming this platform for collaboration. Why should we isolate e-mail?" Dietzen said.

    Earlier this year, Google Maps, one of the first applications to make the benefits of AJAX development clear to a broad audience, emerged. The program enables people to use a mouse to move a map image around the screen.

    Zimbra programmers have used the same techniques to make e-mail clients and servers more interactive. The company's Web-based client
    provides dragging and dropping calendar items and searching for past e-mails--features typically found in desktop software such as Microsoft's Outlook and Lotus Notes.

    In addition, the Web-based client uses XML to combine e-mail with other applications. For example, a tie-in to the Google Maps Web service enables people to mark the location of a meeting with a Google Maps image inside the calendar application. There are also links to some packaged applications that could allow a sales person, for example, to click on a purchase order in an e-mail and pull up the relevant information directly from Oracle Financials.

    AJAX-style development allowed Meebo, a San Francisco-based start-up, to jump into the instant messaging market without compromising on features, co-founder Sternberg said. The Web-based instant messaging client is expected to go into beta testing later this fall.

    Even Microsoft is showing interest in the development technique. The next version of its Hotmail service, code-named Kahuna and now in beta testing, relies heavily on Microsoft's AJAX tooling . The same goes for the next Yahoo Mail client, which went into limited beta testing earlier this month.

    Because these emerging AJAX-style applications are Web-based, they can be hosted outside a company network. They can also run on any operating system rather than just on Windows, analysts said.

    On top of being cross-platform, Web applications can be accessed from multiple locations and from handheld devices or PCs. In addition, the Web approach could make administration of business applications easier, as it provides a built-in mechanism for backing up data and sending out updates, proponents said.

    Developers can also take advantage of XML and Web services standards to fetch information from back-end data sources. For software users, this means that information on a Web page, such a search result or RSS feed, can updated automatically and without a reload of the page.

    For all its promise, widespread use of AJAX still faces some hurdles. The development tools for writing AJAX-style applications are not as sophisticated as for other programming languages, industry executives said. To address this, products designed to make AJAX programming simpler have been released by a few companies, including JackBe, ClearNova and Midnight Coders.

    Microsoft's grip
    Although the idea of a Web-based alternative to Microsoft Office may sound threatening to the software giant, the company's products are deeply entrenched, particularly in the corporate market. The training costs associated with replacing Office alone make switching away from it very unlikely, said Joe Drouin, global chief information officer at TRW Automotive.

    "The Windows-Office platform has become second nature to people," Drouin said. "There would have to be an amazingly compelling business case to convince me to go out and retrain 24,000 people on an all-new desktop environment, an all-new office environment and an all-new way of working."

    For corporations, Microsoft has also gone to significant lengths to bring the benefits of Web server-based administration to Windows on the PC. For example, one feature called ClickOnce which will be available later this year, lets administrators install Windows applications from a server.

    Microsoft executives argue that the rich graphics capabilities of native Windows applications, including multimedia, will outshine Web-only editions.

    "The new kind of applications ISVs (independent software vendors) can make (with Windows Vista) will be dramatically different from what's possible with the Web application model. I think it's clearly differentiated," said Greg Sullivan, group product manager in charge of the Windows Vista client in a recent interview.

    Still, the arrival of Web-based applications with user interfaces as good as those in PC applications is a big change. The shift is big enough to make the Web browser, 10 years after its invention, more appealing as a way for people to work with software.

    "The advent of AJAX has the ability to create a structural shift people didn't see coming," Meebo's Sternberg said. "The Web wasn't ever as functional or useful as client software, and AJAX just knocks that ball out of the park."

    CNET News.com's Mike Ricciuti contributed to this report.

    //================================
    "The Windows-Office platform has become second nature to people."
    --Joe Drouin, global CIO, TRW Automotive
    //================================
    "We're just seeing the tip of the iceberg when it comes to browser-based applications."
    --Dan Grossman, venture capitalist