Kurt Cagle

Subscribe to Kurt Cagle: eMailAlertsEmail Alerts
Get Kurt Cagle via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Related Topics: RIA Developer's Journal, AJAX World RIA Conference

RIA & Ajax: Article

Real-World AJAX Book Preview: The Essential AJAX Pieces

AJAX is a set of technologies that are now all part of most contemporary browsers

This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs for the special pre-order price, click here for more information. Aimed at everyone from enterprise developers to self-taught scripters, Real-World AJAX: Secrets of the Masters is the perfect book for anyone who wants to start developing AJAX applications.

AJAX isn't so much a single technology as it is a set of technologies that are now all part of most contemporary browsers. Because of this factor, it's sometimes difficult to explain what precisely AJAX is, especially the degree to which XML or JavaScript predominates.

This chapter will explore most of the canonical elements of AJAX on the client and get into some of the grittier details about how exactly an AJAX application works. It will also stray a bit off course and show how AJAX applications can use some of the more advanced capabilities on browsers (such as XPath and XSLT) to simplify the underlying development process, though perhaps at the cost of some portability.

The Essential AJAX Pieces
This should be a no-brainer. AJAX stands for Asynchronous JavaScript and XML so it stands to reason that AJAX would have both of these as core pieces (and it does, though interpreting the role of XML varies considerably from user to user in the AJAX space). However, AJAX generally involves considerably more than just these two technologies.

On the client, in particular, what has come to be called AJAX can best be broken down into the following areas:

JavaScript: This provides the scripting language for performing most of the actions (and generally for setting up event management).
XMLHttpRequest: This particular component makes communication between the client and server possible from within a Web page.
HTML/XML Document Object Model: This provides a way of describing a Web page as a tree of interconnected objects.
Cascading Style Sheets (CSS): This language makes it possible to change the visual styling of the page to alter its presentation layer.

Besides these four elements, there are two more that are found in Internet Explorer and Mozilla Firefox:

XSLT: This transforms XML content into other XML content and works quite effectively for building rich objects from data streams.
XPath: This provides a way of navigating around complex XML structures more readily.

These will be covered in greater depth at the end of this chapter.

Whole books have been written on all of these topics, so my goal here is not to teach the basics of JavaScript, DOM programming, or CSS. Instead, I'll be looking at those techniques that may be a little more advanced, but hopefully also be of more use to you as developers. Please check out the references at the end of this book for more information on each of the core technologies.

Examining JavaScript
JavaScript (or ECMAScript, as it's formally known) has been around in various forms since early 1994. It's found in all contemporary Web browsers, and in slightly modified form in the Macromedia/Adobe Flash player, in Adobe PDF, and as a scripting language on both Windows- and Linux-based systems. It's used as the binding language of choice in the Mozilla Firefox and Thunderbird applications

Despite this fairly impressive use record, until comparatively recently JavaScript has been maligned as being too lightweight to be useful in real-world applications, but its gradual re-emergence as part of AJAX has left those JavaScript developers who understood the power of their "light" language feeling more than a trifle smug.

While it's easy to look at JavaScript as being, as its name implies, a scripted variant of Java, this impression is in fact somewhat erroneous. Java is a strongly typed language with an elaborate inheritance mechanism and a foundational class system with classes numbering in the thousands. It has only recently branched into type templates and reflection.

JavaScript, on the other hand, views classes as being particular variants of functions, envisions objects as little more than bundled collections of properties and methods, dynamically assigns type depending on the context, and has only a handful of "core" objects and no foundational class system to speak of. Indeed, while it's possible to inherit classes in JavaScript, in point of fact it's usually far more effective to keep inheritance down to an absolute minimum.

These differences have made for very different ways of programming JavaScript compared to Java. Add to this the question of scope – JavaScript is typically used to automate Web page manipulation and, as such, is generally far more transient than most Java applications – this leads to a situation where the best way to learn JavaScript seriously is to forget that you ever learned Java and take it from scratch.

This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs, click here to order.

More Stories By Kurt Cagle

Kurt Cagle is a developer and author, with nearly 20 books to his name and several dozen articles. He writes about Web technologies, open source, Java, and .NET programming issues. He has also worked with Microsoft and others to develop white papers on these technologies. He is the owner of Cagle Communications and a co-author of Real-World AJAX: Secrets of the Masters (SYS-CON books, 2006).

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.