Introduction

With recent advances in JavaScript, web developers have been able to create an unprecedented user experience in web applications. Breaking free of the "click and wait" paradigm that has dominated the web since its inception, developers can now bring features formerly reserved for desktop applications onto the web using a technique called Ajax.

Ajax is an all-encompassing term surrounding the use of asynchronous HTTP requests initiated by JavaScript for the purpose of retrieving information from the server without unloading the page. These requests may be executed in any number of ways and using any number of different data transmission formats. Combining this remote data retrieval with the interactivity of the Document Object Model (DOM) has bred a new generation of web applications that seem to defy all the traditional rules of what can happen on the web. Big companies such as Google, Yahoo!, and Microsoft have devoted resources specifically towards the goal of creating web applications that look and behave like desktop applications.

This book covers the various aspects of Ajax, including the different ways you can initiate HTTP requests to the server and the different formats that can be used to carry data back and forth. You will learn different Ajax techniques and patterns for executing client-server communication on your web site and in web applications.

Who This Book Is For

This book is aimed at two groups of readers:

  • Web application developers looking to enhance the usability of their web sites and web applications.

  • Intermediate JavaScript developers looking to further understand the language.

In addition, familiarity with the following related technologies is a strong indicator that this book is for you:

  • XML

  • XSLT

  • Web Services

  • PHP

  • C#

  • HTML

  • CSS

This book is not aimed at beginners without a basic understanding of the aforementioned technologies. Also, a good understanding of JavaScript is vitally important to understanding this book. Those readers without such knowledge should instead refer to books such as Beginning JavaScript, Second Edition (Wiley 2004) and Professional JavaScript for Web Developers (Wiley Publishing, Inc., 2005).

What This Book Covers

Professional Ajax provides a developer-level tutorial of Ajax techniques, patterns, and use cases.

The book begins by exploring the roots of Ajax, covering how the evolution of the web and new technologies directly led to the development of Ajax techniques. A detailed discussion of how frames, JavaScript, cookies, XML, and XMLHttp requests (XHR) related to Ajax is included.

After this introduction, the book moves on to cover the implementation of specific Ajax techniques. Request brokers such as hidden frames, dynamic iframes, and XHR are compared and contrasted, explaining when one method should be used over another. To make this discussion clearer, a brief overview of HTTP requests and responses is included.

Once a basic understanding of the various request types is discussed, the book moves on to provide in-depth examples of how and when to use Ajax in a web site or web application. Different data transmission formats, including plain text, HTML, XML, and JSON are discussed for their advantages and disadvantages. Also included is a discussion on web services and how they may be used to perform Ajax techniques.

Next, more complex topics are covered. A chapter introducing a request management framework explores how to manage all of the requests inside of an Ajax application. Ajax debugging techniques are also discussed, including the popular FireBug and Fiddler utilities.

The last part of the book walks through the creation of two full-fledged Ajax web applications. The first, FooReader.NET, is an Ajax-powered RSS reader. The second, called AjaxMail, is an Ajax-enabled email system. Both of these applications incorporate many of the techniques discussed throughout the book.

How This Book Is Structured

This book begins by providing background about the origins of Ajax before moving into actual implementation. Next, the various ways to accomplish client-server communication are discussed, setting the stage for the rest of the book. It is recommended that you read the book straight through, as each chapter builds on information in the previous chapters.

The chapter-level breakdown is as follows:

  1. What Is Ajax? Explains the origins of Ajax, the technologies involved, and where the term originated. Describes how Ajax developed as the web developed and who, if anyone, can claim ownership of the term and techniques.

  2. Ajax Basics. Introduces the various ways to accomplish Ajax communication, including the hidden frame technique and XHR. The advantages and disadvantages of each approach are discussed, as well as guidelines as to when each should be used.

  3. Ajax Patterns. Focuses on design patterns using Ajax. There are a variety of ways to incorporate Ajax into web sites and web applications; these have been organized into a handful of design patterns that describe best practices for Ajax incorporation.

  4. Ajax Libraries. Explores three popular Ajax libraries: the Yahoo! Connection Manager, Prototype, and jQuery. The different approaches of these libraries are compared and contrasted, as well as recreating previous examples using the libraries.

  5. Request Management. Discusses the management of XHR requests for an Ajax application, keeping in mind browser limitations. A methodology for creating a prioritization system is discussed, tying in aspects of the Ajax patterns discussed in Chapter 3.

  6. XML, XPath, and XSLT. Introduces XML, XPath, and XSLT as complementary technologies to Ajax. The discussion centers on using XML as a data transmission format and using XPath/XSLT to access and display information.

  7. Syndication with RSS and Atom. Deals with using Ajax together with the data syndication formats RSS and Atom to create a news-based widgets. Techniques from previous chapters are used heavily.

  8. JSON. Introduces JavaScript Object Notation (JSON) as an alternate data transmission format for Ajax communications. Advantages and disadvantages over using XML and plain text are discussed.

  9. Comet. Discusses the emergence of the server-push architecture called Comet. Several different techniques are discussed for implementing Comet depending upon browser capabilities.

  10. Maps and Mashups. Explores two of the APIs available for Ajax maps: the Google Maps API and the Yahoo! Maps API. Each of the APIs is explored for their capabilities and limitations as well as their use of geocoding.

  11. Ajax Debugging Tools. Discusses various methods of debugging Ajax requests. The FireBug extension for Firefox and the Fiddler tool for Internet Explorer are introduced as a way to debug HTTP requests.

  12. Web Site Widgets. Brings the techniques from the previous chapters into focus by creating Ajax widgets that can be included in your web site.

  13. Ajax Frameworks. Covers three Ajax frameworks: JPSPAN for PHP, DWR for Java/JSP, and Ajax.NET for the .NET framework. Each of these frameworks attempts to automate some part of the Ajax development process.

  14. ASP.NET AJAX Extensions (Atlas). Introduces ASP.NET AJAX Extensions (formerly called Atlas) and how they can simplify the creation of Ajax applications. Assumes usage of .NET 2.0 for server-side code.

  15. Case Study: FooReader.NET. Explores the creation of an RSS news aggregator. This application illustrates the use of server-side proxies, as well as the use of XML in JavaScript.

  16. Case Study: AjaxMail. Walks through the development of a complete web application. This application, called AjaxMail, is an Ajax-based email system that uses many of the techniques described earlier in the book.

What You Need to Use This Book

To run the samples in the book, you will need the following:

  • Windows 2000, Windows Server 2003, Windows XP, or Mac OS X

  • Internet Explorer 5.5 or higher (Windows), Firefox 1.5 or higher (all platforms), Opera 9.0 or higher (all platforms), or Safari 2.0 or higher (Mac OS X).

The complete source code for the samples is available for download from our web site at www.wrox.com.

Conventions

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

NOTE

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

  • We highlight new terms and important words when we introduce them.

  • We show keyboard strokes like this: Ctrl+A.

  • We show file names, URLs, and code within the text like so: persistence.properties.

  • We present code in two different ways:

    In code examples we highlight new and important code with a gray background.
    
    The gray highlighting is not used for code that's less important in the present context, or has been shown before.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at http://www.wrox.com. Once at the site, simply locate the book's title (either by using the Search box or by using one of the title lists) and click the Download Code link on the book's detail page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-471-0949-6.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at http://www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

See Appendix A for more information about what's included with the code download for this book.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to http://www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.

  2. Read the terms of use and click Agree.

  3. Complete the required information to join as well as any optional information you wish to provide and click Submit.

  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset