: Christian Gross
: Ajax Patterns and Best Practices
: Apress
: 9781430201311
: 1
: CHF 36.00
:
: Informatik
: English
: 416
: Wasserzeichen/DRM
: PC/MAC/eReader/Tablet
: PDF

Takes a unique angle on Ajax, providing patterns for application development and best practices for integrating Ajax and REST into rich applications

    Designed to suit all groups of developers across many platforms, who are interested in the hot new topic of Ajax

    Hi h demand for Ajax knowledge. Leading technology companies like Google and Yahoo are looking for developers with intimate knowledge of Ajax



    Christian Gross is a consultant with vast experience in the client/server world. He has consulted for Microsoft on DNA solutions, and he has held consulting positions with Daimler Benz, Microsoft, NatWest, and other major corporations. Gross was a contributor to Professional Active Server Pages, Professional SQL Server 6.5 Administration, Professional NT Internet Information Server Administration, and Programming Microsoft Windows 2000 Unleashed. He is the author of A Programmer's Introduction to Windows DNA.
Chapter 1 Introduction to Ajax (p. 1-2)

Asynchronous JavaScript and XML (Ajax)1 is both something old and something new old because already existing technologies are used, but new because it combines these existing technologies into techniques that very few considered previously. Simply put, because of Ajax a new generation of applications and ideas are bubbling on the developer scene. A very brief definition of Ajax is as follows: Ajax is a technology that complements Web 2.0 and the integration of many web services at once.

This brief definition poses more questions than it answers, as now you are likely wondering what Web 2.0 is and what the integration of many web services are. Web 2.0 can be thought of as the Internet economy.2 Think about something as typical as an encyclopedia, and you will start to think about salespeople who carry extremely heavy books and knock on doors. In a Web 2.0 context, an encyclopedia means Wikipedia (http:// www.wikipedia.org). The Wikipedia project is an open effort by humanity to record itself. Whereas for a traditional encyclopedia a set of writers and editors write about certain topics, Wikipedia is created by people who write about what they know. Get enough people together and you get an encyclopedia that is on the Internet. What is thought-provoking about the Wikipedia project is that anybody can edit it, and therefore it usually contains more current and unusual information than a traditional encyclopedia. In some instances Wikipedia s selfcorrecting capabilities have proven to be problematic, but considering the scale and depth of the project, those instances have been exceptions.

The second part of Ajax is the integration of many web services at once. Ajax allows a higher level of interactivity in a HyperText Markup Language (HTML) page than was possible without Ajax technologies. The result is that an Ajax application changes from a web application to a web service manipulation technology. In a traditional web application, navigating content meant changing HTML pages. With Ajax, navigating content means navigating web services that could be generating HTML content, or Extensible Markup Language (XML) content, or other content.

Pictures Are Worth a Thousand Words

The definition explains Ajax, but you are probably still wondering what Ajax does. There is a saying that a picture is worth a thousand words, and the following images and their associated explanations illustrate best what Ajax does. Map.search.ch was one of the first major Ajax applications, and it illustrates the elegance of what an Ajax application can be. In a nutshell, Map.search.ch is used to find restaurants, houses, parking spots, and more throughout Switzerland. When you surf to the website http://map.search.ch, you will see something similar to Figure 1-1.
Contents at a Glance6
Contents8
About the Author14
About the Technical Reviewer16
Acknowledgments18
Introduction20
CHAPTER 1 Introduction to Ajax24
Pictures Are Worth a Thousand Words25
Another Ajax Example31
Ajax Architecture Basics33
It s About the Data34
It s About the Navigation35
Comparing Ajax to Other Application Types37
Rich-Client Local Installation37
Rich-Client Web Services38
Plain-Vanilla Web Application39
Some Final Thoughts40
CHAPTER 2 The Nuts and Bolts of Ajax42
Ajax for the Impatient42
Understanding REST Theory42
Implementing the REST Data44
Implementing the Ajax Application45
Putting Together Ajax and REST46
Understanding the Ramifications of Ajax and REST47
XMLHttpRequest Details48
Using the Factory Pattern50
Defining an XMLHttpRequest Factory51
Rewriting the Ajax Application to Use a Factory52
Making Asynchronous Requests53
Making Practical Use of XMLHttpRequest57
Implementing an Asynchronous Calling Mechanism57
Calling Domains Other Than the Serving Domain68
Some Final Thoughts74
CHAPTER 3 Content Chunking Pattern76
Intent76
Motivation76
Applicability77
Associated Patterns78
Architecture78
Implementing Order in a Web Application78
Defining the Content Within a Content Chunk82
Implementation83
Implementing the HTML Framework Page83
Injecting Content by Using Dynamic HTML85
Binary, URL, and Image Chunking92
JavaScript Chunking95
Pattern Highlights100
CHAPTER 4 Cache Controller Pattern102
Intent102
Motivation102
Applicability104
Associated Patterns105
Architecture105
HTML and HTTP Cache Directives105
HTTP Expiration Caching Is a Bad Idea (Generally)107
Better Approach: Using HTTP Validation107
Some Findings Regarding Server-Side Caching109
Defining Static HTTP Validation111
Defining Dynamic HTTP Validation112
Implementation114
Implementing the Passive Cache114
Implementing the Server Side of the HTTP Validator123
Pattern Highlights131
CHAPTER 5 Permutations Pattern134
Intent134
Motivation134
Applicability139
Associated Patterns139
Architecture139
Understanding Why the Resource Is Separated from the Representation140
Using Cookies and HTTP Authentication to Authorize Access Only142
Using Cookies145
An Example Book Application146
Implementation151
Rewriting URLs151
An Example Shopping Cart Application158
Pattern Highlights173
CHAPTER 6 Decoupled Navigation Pattern176
Intent176
Motivation176
Applicability180
Associated Patterns182
Architecture183
Implementation185
Implementing the Action Functionality185
Defining and Implementing the Common Data Functionality195
Implementing the Presentation Functionality210
Using HTML Components215
Pattern Highlights2