One of the most annoying things about the Web page paradigm is that you have to reload the page whenever you want to do something on the server side. If you want to do a site search, it's sprinkled across two pages.
On the first page, the user will enter a search term, then clicks a submit button to get to the second page where the search results are returned. If the user wants to filter or sort the search results it's usually refreshed again and each result is redisplayed in its filtered state.
Lately there's been a movement to help improve the Web by eliminating these constant page refreshes. Macromedia's Rich Internet Application (RIA) push with Flash and Flex has been at the forefront of this effort, however Flex' entry price has made it prohibitive for many ColdFusion Developers. That's where AJAX comes in. It's an alternate way to create a RIA and relies on technologies built into most browsers, making it completely free.
Dissecting AJAX
AJAX stands for Asynchronous JavaScript and XML. It's not a single technology, but rather a combination of different technologies that are used to create a Rich Internet Application feel. You've probably seen examples of this kind of application. Google uses AJAX a lot on such services as maps.google.com. After bringing up a location, you can click and drag the map, zoom in or out, or even bring up directions to and from the location. All this is done without any screen refreshes. You have to admit that the interface is pretty sweet. (Note: Yahoo has a similar mapping application, built entirely in Flex at http://maps.yahoo.com/beta.)
Since AJAX is a combination of technologies you're going to want to know what you're getting into before going any farther, right? I thought so. Here's the list:
XHTML: To start with you need a display language. Most resources on AJAX say you have to use XHTML, but regular HTML will work too.
XMLHttpRequest: The XMLHttpRequest object lets you retrieve data from the server without refreshing the page. It's a JavaScript object implemented in most major browsers. As the XMLHttpRequest object is being called, the user can do other things on the page. This is where the "asynchronous" part of the acronym comes in.
iFrames: iFrames are in-line frames and are sometimes used as an alternative to the XMLHttpRequest object. A regular frame will divide the browser window into multiple separate pages, but an in-line frame embeds one page inside another. I won't get into any iFrames details in this article.
XML: You all know what XML is, right? As a refresher, it's a way to describe data. If you need more details, read the article in this column from August 05 at http://coldfusion.sys-con.com/read/117667.htm.
Document Object Model: The document object model defines your HTML page through a programmer API.
JavaScript: I'm sure you all know what JavaScript is too. It's the most common language used for providing client-side functionality to HTML pages.
How do all these different technologies work together using AJAX? Well, it generally works something like this:
First, the user comes to your page and the page loads. Something (depending on what your page does) is loaded and displayed to the user.
The user does something such as clicking a link. Instead of reloading the page (as would happen in a normal Web app), that link fires off a JavaScript function.
The JavaScript function uses XMLHttpRequest object to retrieve XML data from the server.
Then the JavaScript parses the XML Data and through the Document Object Model will change the page without a refresh.
So the user gets to see more data quicker without the annoying page refreshes. That's fantastic, right? Why isn't everyone using this? Well, as with all things, AJAX isn't perfect. There are drawbacks:
Development Time: Working with AJAX will bring you back to the old days of Web development, especially if you want any kind of cross-compatibility. There are different syntaxes for creating the XMLHttpRequest object in IE vs Netscape/Firefox, which can lead to extended development times.
User Experience: When used properly, an AJAX can enhance the user experience. However, when used improperly it can make it horrendous. Since the page isn't reloading, what happens when the user hits the back button? He'll leave the application altogether. I bet he expected to go to the app's "previous state." What happens when the user bookmarks a page? He'll go the "initial" state of the app. There are workarounds, of course, but they're not trivial to implement.
Searches: The single-page nature of the app makes indexing by search engines a tetchy proposition at best.
Response Times: The very thing that works for you (no page reloads) can also work against you. What happens if you're retrieving a lot of data from the server? And the user is given no indication that something is happening.
JavaScript: JavaScript must be enabled for an AJAX app to work. If JavaScript is disabled, your user isn't going to have a lot of fun with an AJAX app.
Accessibility: AJAX is, most likely, not going to meet accessibility guidelines. If this is a goal of your project you're going to have to provide a fallback option. That means developing two paths to the same goal.
There are a few real simple examples of AJAX that you've probably used or seen that existed long before the term AJAX was conceived. Have you ever rolled your mouse over a graphic navigation button only to have that graphic change? JavaScript rollovers can be considered a precursor to AJAX. They do use JavaScript and they do change the state of the page. Have you turned on or off a DHTML layer on a page based on some selection by the user? This is another example of AJAX. If an application has a select box with an "other" option in it I'll often use DHTML to display an input text box if "other" is selected. If other isn't selected the input box is hidden. Both of these are simple examples of changing the page without a screen refresh. They don't go out to the server to get data, but they still fit the RIA paradigm.
Putting This All Together
Let me show you how this all comes together, so you can actually do something useful. The first step in the process is to initialize the XMLHttpRequest object. Unfortunately, there's not consistent way to do this across browsers:
About Jeffry Houser Jeffry Houser has been working with computers for over 20 years and in Web development for over 8 years. He owns a consulting company and has authored three separate books on ColdFusion, most recently ColdFusion MX: The Complete Reference (McGraw-Hill Osborne Media).
Jeff Houser wrote:
Christopher,
I have no access to the
"backend" world of
sys-con; I just write and
submit articles.
I can re-iterate that it
was written last January
for the February issue of
CFDJ. I can't comment on
the publishing (or
re-publishing) of it w/ a
new date. It appears
that sys-con corrected
the mistake. Nor can I
comment on what gets
e-mailed to subscribers
and when. None of that
is anything I am involved
with.
You are right that there
is no ColdFusion in the
article, and as such the
title is misleading.
It's probably something I
should have caught and
corrected in the
proof-read. But, I'm not
perfect so you'll have to
accept my apology for
that.
A lot of articles for my
column (which is a
beginner's column) have
no direct relation to CF,
but rather deal with
topics that affect
ColdFusion d...
Christopher Jordan wrote:
Jeff,
Try typing "Dissecting
ColdFusion and AJAX" into
Google and then looking
at the cached page.
You'll see what I saw
before you (or your
editor) corrected their
mistake. The article says
it published Nov. 1,
2006.
Nice try.
If your intent was to
write an article that
guided the user through
the mechanics of AJAX,
then don't title your
article "Dissecting
ColdFusion and AJAX". The
title is extreemly
misleading. You said
very, very little about
ColdFusion or how it
plays with Ajax. Your RSS
Feed example seemed to
have nothing to do with
ColdFusion (this is the
ColdFusion Developer's
Journal, right?)
A let down of an article
to be sure. Perhaps you
guys ought to have a
system indicating the
level at which you will
be addressing topics.
Beginner, intermediate,
advanced.
Also, as I asked your ...
Jeff Houser wrote:
Christopher,
The article was written
for the February issue of
CFDJ, my initial draft is
dated from 11 months ago.
As the duty editor
pointed out, the article
has been on the site
since May 2006, I'm not
sure why you think it was
posted in November.
That said, I think its
important to understand
the mechanics behind
"AJAX" and that was the
focus of the article.
Yes, there are plenty of
frameworks and script
libraries as you
mentioned, but if I had
to write another
beginner's article on the
subject, I'd concentrate
again on underlying
mechanics of AJAX, not on
the frameworks.
Duty Editor wrote:
Christopher,
Thanks for the feedback.
This article was chosen
as part of a "Best of
2006" program, in which
we wished to recognize
those writers whose work
was enjoyed in the course
of '06 by our readers.
18,607 people have
enjoyed this article
since it was first
published on March 8,
2006.
Sorry for any
misunderstanding. For
up-to-the-minute coverage
of AJAX, you no doubt are
aware of AJAXWorld
Magazine,
http://ajax.sys-con.com,
which is updated daily -
sometimes hourly.
Duty Editor
SYS-CON Media
Christopher Jordan wrote:
Where the hell have you
been? Under a rock? The
first page of your
article made you seem so
completely out of touch
that I didn't even want
to read the second page.
I realize this article
was published on Nov. 01
of this year, but dude,
c'mon, there were heaps
of things happening last
month to help ease
writing ajax and
javascript. YUI? Dojo?
Prototype? ... and my
favorite: jQuery!
Gimme a break. Why am I
just now (Dec. 19, 2006)
getting an email about an
article written over a
month ago? Get on the
ball guys... or get left
behind
CFDJ News Desk wrote: One
of the most annoying
things about the Web page
paradigm is that you have
to reload the page
whenever you want to do
something on the server
side. If you want to do a
site search, it's
sprinkled across two
pages.
SYS-CON Brazil News Desk
wrote: One of the most
annoying things about the
Web page paradigm is that
you have to reload the
page whenever you want to
do something on the
server side. If you want
to do a site search, it's
sprinkled across two
pages.
SYS-CON India News Desk
wrote: One of the most
annoying things about the
Web page paradigm is that
you have to reload the
page whenever you want to
do something on the
server side. If you want
to do a site search, it's
sprinkled across two
pages.
CFDJ News Desk wrote: One
of the most annoying
things about the Web page
paradigm is that you have
to reload the page
whenever you want to do
something on the server
side. If you want to do a
site search, it's
sprinkled across two
pages.
j j wrote: One of the
most annoying things
about the Web page
paradigm is that you have
to reload the page
whenever you want to do
something on the server
side. If you want to do a
site search, it's
sprinkled across two
pages.
SYS-CON Italy News Desk
wrote: One of the most
annoying things about the
Web page paradigm is that
you have to reload the
page whenever you want to
do something on the
server side. If you want
to do a site search, it's
sprinkled across two
pages.
CFDJ News Desk wrote: One
of the most annoying
things about the Web page
paradigm is that you have
to reload the page
whenever you want to do
something on the server
side. If you want to do a
site search, it's
sprinkled across two
pages.
AJAXWorld News Desk
wrote: One of the most
annoying things about the
Web page paradigm is that
you have to reload the
page whenever you want to
do something on the
server side. If you want
to do a site search, it's
sprinkled across two
pages.
SYS-CON Belgium News Desk
wrote: One of the most
annoying things about the
Web page paradigm is that
you have to reload the
page whenever you want to
do something on the
server side. If you want
to do a site search, it's
sprinkled across two
pages.
SYS-CON Italy News Desk
wrote: One of the most
annoying things about the
Web page paradigm is that
you have to reload the
page whenever you want to
do something on the
server side. If you want
to do a site search, it's
sprinkled across two
pages.
John Dobson wrote: A very
helpful article. It might
be useful to add that the
getRSS() function must
actually be invoked
somewhere, for example in
the onLoad attribute of
the BODY tag.
In the online edition of
the article, there is a
closing curly brace
missing at the end of the
first block of
JavaScript.
From Application
Virtualization to Xen, a
round-up of the
virtualization themes &
topics being discussed in
NYC June 23-24, 2008 by
the world-class speaker
faculty at the 3rd
International
Virtualization Conference
& Expo being held by
SYS-CON Events in The
Roosevelt Hotel, in mi
DreamFace DataWidgets
have gotten a lot of
press lately, but what
are Woodgets? DreamFace
Interactive CEO, Olivier
Poupeney gets specific
about woodgets while
presenting key
differentiators of
DreamFace's Web 2.0 Open
Source Framework in his
interview with Jeremy
Geelan for SYS-C
At Java One this week Sun
has been selling its year
-old-but-still-upcoming -
and definitely
late-to-the-party - Adobe
AIR- and Microsoft
Silverlight-competitive
JavaFX Rich Client
environment as a
potential
revenue-generator capable
of putting ads on mobile
applications and JavaF
Payless Car Rental has
launched an iPhone and
iPod Touch optimized
website. Payless Car
Rental is a car rental
agency that built a
customized version of its
website for the iPhone
and iPod Touch. The
homepage of Payless'
iPhone interface also
features a 'Call to Book'
button that
Alpha Software is now
shipping Alpha Five
Platinum Edition, the
ninth release of the
company's flagship Web
database development
platform. It's a
development tool that can
visually build
AJAX-powered
applications, integrate
SQL databases with
drag+drop simplicity, and
deliver ent
May. 15, 2008 03:45 PM
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice: