Introducing Ajax | WebReference

Introducing Ajax

'; figDoc.write(zhtm); figDoc.close(); } // modified 3.1.99 RWE v4.1 -->
[next]

Introducing Ajax

By Ed Woychowsky

A little more than a year ago, an article by Jesse James Garrett was published describing an advanced web development technique that, even though individual components of it have existed for years, few web developers had ever stumbled across. I can guess the reason for this lack of knowledge; basically, in the last few years, the need to produce measurable results has gotten in the way of the need to practice our craft. Or, as a former manager of mine would say, it's "that mad scientist stuff," except, as I recall, he used another word in place of stuff. Unfortunately, nine times out of ten, the need to produce measurable results gets in the way of "that mad scientist stuff."

However, it's the tenth time that's important. The article didn't stop at just describing the technique; it went on to say that Google used the very same technique. Invoking that single name, Google, was enough to change a point of view. Quicker than you could say, "Igor, the kites!" the phrase "that mad scientist stuff" morphed into "Why aren't we doing it this way?" The reason for this change of perception is that the name Google made this a technique that could produce measurable results. All it took was that single name, Google, to make using the XMLHttpRequest object so that the browser could communicate with the server without the page ever unloading and reloading into an acceptable practice.

This chapter introduces you to that practice, the practice of updating web pages with information from the server. Beyond the XMLHttpRequest object, which has been around for several years as a solution looking for a problem, there is nothing weird needed. Basically, it is how the individual pieces are put together. When they're put together in one way, it is nothing more than a pile of parts; however, when put together in another way, the monster essentially rises from its slab.

2.1 Not a Mockup

A few years ago, I demonstrated an application that did what I just described. The demo ran for more than 2 hours with the same questions repeated over and over.

"It's a mockup, right?"

"No, it is the actual application."

"It can't be. The screen doesn't blink."

"That's because XML, HTTP, and SOAP are used to get the data directly from the server. JavaScript then updates only the parts of the page that have changed."

"It's a mockup, right?"

And so on. It took the client more than 2 hours to realize that the database was actually being updated without the page "blinking," as he referred to it.

2.2 A Technique Without a Name

Now, if I had been smart, I would have given the technology a name then and there, and thus ensured my place in Web history, shutting up the client as well. After all, a name is a thing of power, and the client, not wanting to sound stupid for not knowing what the acronym meant, would have saved more than 2 hours of my life that were spent re-enacting the scene of peasants with pitch forks from the 1931 version of Frankenstein, minus the tongs. Unfortunately, I drew an absolute blank and just called it as it was.

With apologies to the people who make the cleanser and the detergent, legend has it that the original Ajax was the second most powerful of the Greek warriors at Troy. Even though he had some issues (who in the Illiad didn't?), his strength and skill in battle were second to none (well, okay, second only to Achilles). In naming the technology Ajax, Jesse James Garrett gave the technology both Ajax's strengths and issues.

2.2.1 Names

An old idea dates back to the dawn of human civilization that to know someone's or something's true name is to have power over that person or thing. It is one of the basic concepts of what is commonly referred to as magic, and although magic isn't real, the idea that names can hold power isn't very far from the truth. Consider, if you will, a resumé. If ever a document held names of power, a resumé is it. Not very long ago, resumés invoking words such as JavaScript, DHTML, and XML were looked upon with envy, perhaps even awe. After all, for a little while, it seemed as though web developers were rock stars that, thankfully, were never asked to sing. Unfortunately, those names are now considered passé or even a little old-fashioned.

In his essay describing this web development technique, Mr. Garrett did one final thing; he gave it a name, Ajax, and thus gave us power over it. The acronym refers to Asynchronous JavaScript And XML, and whether you love or hate the name, the technology now has a name. At the very least, this naming means that we can describe what we've been doing at work. Ajax is a lot easier to say than, "I've been using client-side JavaScript, SOAP, and XML to obtain data directly from the server using XMLHTTP instead of the standard unload/reload cycle."


[next]

URL: