O'Reilly logo

Ajax: The Definitive Guide by Anthony T. Holdener III

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preface

Ajax melds together existing technologies to help developers give web users a more advanced browsing experience. By utilizing XHTML, CSS, JavaScript, and XML, all tried-and-true technologies, along with the XMLHttpRequest object, you can turn browsers into application platforms that closely mirror desktop applications. This capability is allowing existing web sites to convert to Web 2.0 sites, while increasing the number of new web applications that can be found on the Internet today.

Not that long ago, some web technologies, especially JavaScript, were losing their user base as developers turned their attention to other technologies, such as Flash, that could provide more of the functionality that was needed. The coining of Ajax in 2005 gave JavaScript the shot in the arm that some developers felt was sorely needed, and since then, some truly wonderful things have been done with JavaScript that were never thought possible before.

New innovations, together with the functionality of Ajax, have given the Web a new look and appeal. Ajax: The Definitive Guide explores what you can do with Ajax to enhance web sites and give them a Web 2.0 feel, and how additional JavaScript enhancements can turn a web browser and web site into a true application. Even before that, you will get a background on what goes into today’s web sites and applications. Knowing what comprises Ajax and how to use it helps you apply it more effectively and integrate it with the latest web technologies (advanced browser searching, web services, mashups, etc.). This book also demonstrates how you can build applications in the browser, as an alternative to the traditional desktop application.

Ajax is giving developers a new way to create content on the Web while throwing off the constraints of the past. Web 2.0 technologies are being integrated with Ajax to give the Web a new punch that could only be achieved before with browser plug-ins. Ajax is helping to redefine how we all should look at the Web, and I hope this book puts you on the path to defining your own Web 2.0 applications.

Who Should Read This Book

This book is intended for two very different types of people: web developers, and project managers or other higher-level people who do not necessarily need to know the nitty-gritty details but would benefit from a general overview of how this Ajax stuff works. The different parts of the book will reflect these different audiences.

Web Developers

For web developers, this book assumes the following:

  • You have had some experience with HTML/XHTML.

  • You have experience using CSS, and you understand the principles behind separating presentation from content.

  • You understand JavaScript syntax and have written scripts with it.

  • You are comfortable with server-side scripting in at least one language, whether it be ASP.NET, PHP, Python, or something similar.

  • You have some experience with relational databases and how to retrieve data from them.

This book does not expect you to be an expert in all of these skills, but it does expect that you can figure things out on your own or that you can get help from another resource (another book on the technology, perhaps) so that you can follow along with the examples presented.

Server-side code examples throughout the book will use PHP, as it seems to be the most readily understandable to the widest range of developers.

Managers

Project managers reading this book may not need such a rigid set of prerequisites. This book expects that you have seen web technology before and that you understand the concept of client-side and server-side development. It also expects that you can recognize HTML, CSS, and JavaScript, though there is no need to have ever done anything with them. Finally, this book expects that Internet terms and phrases are not foreign to you so that you can follow along with the examples. Managers will probably want to spend more time on the first three chapters to get a broad idea of how Ajax fits into the Web and into application development.

How This Book Is Organized

This book consists of five parts, each focusing on a different aspect of Ajax. It is certainly not necessary to read it from beginning to end, though later parts of the book do build on ideas from previous parts. The five parts of the book comprise 23 chapters and four appendixes. Part I is intended for project managers looking to get a leg up on Ajax, or for anyone who is looking for its fundamentals. The rest of the book focuses on using Ajax from a programming point of view.

Part I, Ajax Fundamentals, explains the basic technologies that form the core of Ajax and building Ajax applications:

Chapter 1

Demonstrates how the first web sites were completely data-driven sites without the benefit of tools to improve page presentation, whereas today’s Web is completely different. From the tools that are used to develop sites to the fact that the Web is now very much driven by a combination of media and data, today is nothing like yesterday.

Chapter 2

Explains the nature of web site construction in the past versus the applications they have become, and the fact that they require the same process and design approach utilized by developers for regular desktop applications.

Chapter 3

Shows the technologies available on the server side of web applications, briefly discussing each and how you can use them as a backend to an Ajax application. An introduction to databases rounds out the topic.

Chapter 4

Gives the foundation for all Ajax requests using the XMLHttpRequest object, and explores XML and JSON responses and their advantages and disadvantages. Frameworks that make Ajax simpler are also addressed.

Chapter 5

Explores manipulation and utilization of the DOM for JavaScript, examining differences between Internet Explorer’s handling of the DOM versus that of other browsers. This chapter also gives an overview of everything necessary for a developer to work with the DOM.

Chapter 6

Examines the different parts of a web interface and how to lay out an Ajax application so that it is usable, functional, visually pleasing, and accessible.

Part II, Ajax Foundations, describes how these technologies are applied in an Ajax web application:

Chapter 7

Shows the different components that make up a web application and how you can enhance them using Ajax. This chapter also explores how some Ajax techniques can break browser functionality.

Chapter 8

Examines how to properly create a table, enhance it, and add functionality with Ajax. It also discusses the different uses for Ajax-enhanced lists.

Chapter 9

Explores frames and iframes and their use before XHTML was introduced, and explains how to emulate their behavior using XML with Ajax, JavaScript, and CSS.

Chapter 10

Examines how to create navigation controls that do not rely on the default browser’s window to display messages to the user, by using Ajax to transport information back and forth between client and server.

Chapter 11

Shows how to customize the user’s experience with an application that uses Ajax to send new data to the client when the user requests it, giving the application a Web 2.0 feel.

Chapter 12

Shows how to handle errors thrown by the application, how to use Ajax to send messages back to the server when it is called for, and how to determine when to display errors to the user.

Chapter 13

Examines the traditional method for animating images on the Internet, the disadvantages of using the GIF format, and the advantages of the PNG format. Then this chapter shows how you can use PNGs for animation on the Web and how to use Ajax to asynchronously download images in the background.

Chapter 14

Explains the significance of forms on the Web, regardless of the backend markup used, and shows the additions for making forms accessible. Then this chapter examines how you can build custom form types to follow the style of the overall page, and how Ajax is used in Web 2.0 forms.

Chapter 15

Shows how Ajax can aid in the validation of data in an XHTML form without requiring a lot of extra time on behalf of the client, and where validation should take place in a web application.

Part III, Ajax in Applications, shows you how to integrate Ajax into applications to create faster and more responsive web components:

Chapter 16

Explores available methods for searching pages on a site, their advantages and disadvantages, and how you can leverage Ajax to bring more intelligent and helpful functionality to searching.

Chapter 17

Examines web services and their role on the Internet, exploring the different protocols that are used—from SOAP to REST and everything in between—and shows how you can take advantage of these services with Ajax behind the scenes.

Chapter 18

Gives a brief introduction to some of the web services that are available on the Internet, and how to use the APIs that make up the frontend to these services. This chapter also shows how JavaScript and Ajax can take advantage of these services in creating dynamic content.

Chapter 19

Explains how mashups are created from different web services and how Ajax can bring together services in a way that makes them even more seamless than the original mashups.

Chapter 20

Shows how you can use the different techniques you learned in the first parts of this book to develop components for business applications, and how you can use these components to build a business mashup that has desktop application functionality.

Chapter 21

Shows how to build on the techniques you learned earlier in this book to develop an Internet game that relies on JavaScript and Ajax without the need for browser plug-ins. This chapter also examines the different gaming genres and explains which ones make the best Internet games for Ajax.

Part IV, Wrapping Up, summarizes how to best structure Ajax applications, and how to write them with optimization in mind:

Chapter 22

Explains modular coding through all aspects of the application, from the XHTML markup, CSS styling, and JavaScript functionality on the client side, to server modules and SQL stored procedures on the server side, and what this programming technique brings to an application.

Chapter 23

Explores techniques that you can use on both the client side and the server side of an Ajax application to make it run as quickly and efficiently as possible in light of the web technologies used.

Part V, References, contains the appendixes that refer you to important parts of Ajax development:

Appendix A

Discusses XML and XSLT, how to use them, and how to leverage them within a web framework.

Appendix B

Discusses the major JavaScript frameworks, libraries, and toolkits—including Prototype, script.aculo.us, Dojo, Ajax.NET, the Yahoo! User Interface, and others—showing how each implements an Ajax wrapper or manipulates XML.

Appendix C

Discusses some of the major web services currently available on the Internet, along with the protocol(s) used to implement the APIs, and whether they are free.

Appendix D

Discusses the major risks associated with implementing Ajax, such as security, default browser functionality, and accessibility, so that developers know what to expect regarding the Ajax and Web 2.0 technologies.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, filenames, and file extensions.

Constant width

Indicates computer coding in a broad sense. This includes commands, options, variables, attributes, keys, requests, functions, methods, types, classes, modules, properties, parameters, values, objects, events, event handlers, XML and XHTML tags, macros, and keywords.

Constant width bold

Indicates commands or other text that the user should type literally.

Constant width italic

Indicates text that should be replaced with user-supplied values or values determined by context.

Tip

This icon signifies a tip, suggestion, or general note. You’ll also see notes regarding the WCAG guidelines. Even if you aren’t interested in accessibility specifically, these are useful best practices.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Ajax: The Definitive Guide, by Anthony T. Holdener III. Copyright 2008 Anthony T. Holdener III, 978-0-596-52838-6.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/9780596528386

You can also download the examples from the author’s web site:

http://ajax.holdener.com/

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com/

Safari® Books Online

When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

I could never have imagined when I started writing this, my first book, just how much work and time would go into it, or how I would rely on so many others to complete this undertaking.

First and foremost, I want to thank my wife, Sarah, for her love, support, and understanding. Sarah, without you, I never would have succeeded in this endeavor. I love you with all my heart. Thank you for allowing me the late nights and countless weekends to work toward this dream. You have sacrificed so much of your life taking care of things while I could not, and for that, I do not have the words to express my gratitude.

I want to thank Kate and Tony for their understanding that Daddy was not there for the better part of a year. I hope that as you get older, you will use this as an example of knowing that your dreams are attainable with hard work. I love you both, and I hope to make up the time that I have missed. Kate and Tony, Daddy is not working on his ‘puter.

I want to thank my family, and that goes to everyone who chipped in and helped with the kids and I do not even know what else, as I worked away on my laptop. All of you gave up countless hours of your own time so that I could write. It humbles me to know I have so much love and support around me.

I want to thank Gateway EDI, Inc. for their willingness to work with me as I crunched to get this book finished. It was reassuring to know that I had that support from them, and it made it less stressful down the home stretch.

I want to thank all of my reviewers; no matter how small your contribution, I am grateful for the comments, suggestions, and corrections that I received. Thanks go to John Aughey, Prerit Bhakta, Zachary Kessin, Steve Olson, Bruce W. Perry, Stacy Trease, and Chris Wells—all of the work has been much appreciated.

I want to thank Simon St.Laurent, my editor, for calming me down when I would start to panic, working with me to give me the time that I needed, and giving me the chance to write this book in the first place. This whole process, being my first and, hopefully, not last, was made almost painless with your help and guidance. I cannot begin to thank you enough.

I also want to thank everyone else who helped get this book ready for production. Thanks to Audrey Doyle for all of the catches, corrections, and changes that have made this so much more readable. Thanks to Rachel Monaghan for all of the work you put into the production of this book, as well as the proofreading. Thank you, Karen, for giving me such a great animal! And thanks to Ellen, David, Jessamyn, and everyone else who made this book what it is.

I have spent more than a year working to see this book become a reality. Everything else in my life took somewhat of a backseat as this happened. I want everyone to know that with the publication of this book comes the completion of one of my life goals—I could not have done it without all of the support that I received.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required