- ホーム
- > 洋書
- > ドイツ書
- > Mathematics, Sciences & Technology
- > Computer & Internet
- > internet, data communication, networks
Full Description
Ajax burst onto the Web development scene by offering highly interactive, desktop-like Web applications that can be deployed through any modern Web browser without the need for special plug-ins. Ajax is built on existing Web technologies such as JavaScript, HTML, and CSS, and it is used in conjunction with your favorite server-side language. Foundations of Ajax explains how to combine these technologies effectively to implement Ajax into your new or existing Web applications. Like you, we are developers who are in the trenches, tasked with building Web-enabled applications that provide real value to our customers. As the Web continues to grow, the demand for more expressive and engaging interfaces will continue to increase. Much of the early hype surrounding Ajax centered on its use by Internet powerhouses such as Google and Amazon. However, just because the initial forays into Ajax were pioneered by leading software development firms doesn't mean your application wouldn't also benefit from these techniques. You already know how to develop Web applications, so this book uses specific, focused examples to teach the Ajax tools and techniques you'll need to bring your applications to life. Armed with this book and your existing development expertise, you too will be able to apply Ajax techniques to your application to enrich the end users experience. When we first saw the potential of Ajax, we knew we had to start leveraging it for our own applications. Along the way weve learned some hard-earned knowledge that we thought needed to be shared with the rest of the development community. With this book, you'll be able to easily extend your own applications with Ajax and have fun while doing it. We hope that someday well be reading about your great Ajax-enabled application!
Contents
Foundations of Ajax Ryan Asleson Nathaniel T. Schutta Foundations of Ajax Copyright (c) 2006 by Ryan Asleson and Nathaniel T. Schutta All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN (pbk): 1-59059-582-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Ewan Buckingham Technical Reviewer: Keith Harvey Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser Production Director and Project Manager: Grace Wong Copy Edit Manager: Nicole LeClerc Copy Editor: Kim Wimpsett Assistant Production Director: Kari Brooks-Copony Production Editor: Linda Marousek Compositor: Linda Weidemann, Wolf Creek Press Proofreader: Patrick Vincent Indexer: Tim Tate Artist: Kinetic Publishing Services, LLC Interior Designer: Van Winkle Design Group Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com. The information in this book is distributed on an as is basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. Contents About the Authors ... xiii About the Technical Reviewer ... xv Acknowledgments ... xvii Introduction ... xix ■CHAPTER 1 Introducing Ajax ... 1 A Short History of Web Applications ... 1 Browser History ... 2 The Evolution of Web Applications ... 3 CGI ... 3 Applets... 4 JavaScript ... 5 Servlets and ASPs and PHP ... Oh My! ... 6 Flash... 9 The DHTML Revolution ... 10 The XML Derivatives ... 10 The Fundamental Problem ... 12 Ajax... 13 The Usability Question ... 16 The Skill Set ... 17 Usage... 19 Design Considerations ... 20 Summary ... 20 ■CHAPTER 2 Using the XMLHttpRequest Object ... 23 Overview of the XMLHttpRequest Object... 23 Methods and Properties ... 24 An Example Interaction... 26 GET vs. POST ... 28 Remote Scripting ... 29 Overview of Remote Scripting ... 29 A Remote Scripting Example ... 29 vii How to Send a Simple Request... 31 A Simple Request Example ... 32 A Word About Security... 34 DOM Level 3 Load and Save ... 35 The DOM ... 36 Summary ... 37 ■CHAPTER 3 Communicating with the Server: Sending Requests and Processing Responses... 39 Processing the Server Response ... 39 Using the innerHTML Property to Create Dynamic Content ... 39 Parsing the Response As XML ... 42 Dynamically Editing Page Content with the W3C DOM ... 48 Sending Request Parameters ... 55 Sending Request Parameters As XML ... 62 Sending Data to the Server Using JSON ... 67 Summary ... 73 ■CHAPTER 4 Implementing Basic Ajax Techniques ... 75 Performing Validation ... 75 Reading Response Headers... 79 Dynamically Loading List Boxes ... 83 Creating an Autorefreshing Page ... 90 Displaying a Progress Bar ... 95 Creating Tooltips ... 101 Dynamically Updating a Web Page... 106 Accessing Web Services... 115 Providing Autocomplete ... 122 Summary ... 128 ■CHAPTER 5 Building the Ultimate Ajax Developer s Toolbox ... 131 Documenting JavaScript Code with JSDoc... 131 Installation... 132 Usage... 132 Validating HTML Content with Firefox Extensions ... 135 HTML Validator ... 136 Checky... 138 ■CONTENTS viii Searching for Nodes Using DOM Inspector... 140 Performing JavaScript Syntax Checking with JSLint ... 143 Performing JavaScript Compression and Obfuscation ... 145 Using the Web Developer Extension for Firefox ... 147 Implementing Advanced JavaScript Techniques ... 148 Object-Oriented JavaScript via the prototype Property ... 148 Private Properties and Information Hiding with JavaScript ... 153 Classical Inheritance in JavaScript ... 154 Putting It All Together ... 155 Summary ... 158 ■CHAPTER 6 Testing JavaScript with JsUnit... 161 Rising to the JavaScript Challenge... 161 Introducing the Test-First Approach ... 161 Introducing JUnit ... 163 Exploring JsUnit ... 164 Getting Started ... 164 Writing Tests ... 164 Running Tests ... 179 Using Standard and Custom Query Strings ... 184 Working with JsUnit Server ... 189 Getting Help ... 191 What Else Can You Use? ... 192 Summary ... 192 ■CHAPTER 7 Exploring JavaScript Debugging Tools and Techniques ... 193 Debugging Ajax Requests with Greasemonkey ... 193 Introducing Greasemonkey ... 194 Using an XMLHttpRequest Debugging User Script for Greasemonkey ... 194 Inspecting Ajax Requests and Responses with the XMLHttpRequest Debugging User Script ... 194 Debugging JavaScript... 196 Using Firefox JavaScript Console ... 197 Using Microsoft Script Debugger ... 198 Using Venkman... 201 Summary ... 217 ■CONTENTS ix ■CHAPTER 8 Putting It All Together ... 219 Introducing Patterns ... 219 Implementing the Fade Anything Technique (FAT) ... 219 Implementing Auto Refresh ... 220 Implementing a Partial Page Paint ... 220 Implementing a Draggable DOM... 221 Avoiding Common Gotchas ... 222 Learning Where to Go for More ... 224 Using a Framework ... 226 Introducing Taconite ... 226 The Theory of Taconite ... 227 The Solution ... 227 What Does Taconite Do with the Content? ... 228 Introducing Dashboard Applications... 229 Building the Ajax Dashboard with Taconite ... 230 Introducing the General Features ... 230 Introducing the Design Features ... 232 Analyzing the Code ... 233 Analyzing the Weather Forecast Component... 235 Analyzing the Headline News Component... 242 How Does the Automatic Refreshing Work? ... 245 Building a Better Autocomplete... 247 Summary ... 249 ■APPENDIX A Developing Cross-Browser JavaScript ... 251 Appending Rows to a Table ... 251 Setting an Element s Style via JavaScript ... 252 Setting an Element s class Attribute... 253 Creating Input Elements ... 253 Adding Event Handlers to Input Elements ... 254 Creating Radio Buttons... 255 Summary ... 256 ■CONTENTS x ■APPENDIX B Introducing Ajax Frameworks... 257 Browser-Side Frameworks ... 257 Dojo ... 257 Rico ... 258 qooxdoo... 258 TIBET ... 258 Flash/JavaScript Integration Kit ... 259 Google AJAXSLT ... 259 libXmlRequest... 259 RSLite... 259 SACK ... 260 sarrisa ... 260 XHConn ... 260 Server-Side Frameworks ... 261 CPAINT ... 261 Sajax ... 261 JSON/JSON-RPC ... 261 Direct Web Remoting... 261 SWATO... 262 Java BluePrints ... 262 Ajax.Net ... 262 Microsoft s Project Atlas ... 262 Ruby on Rails ... 263 ■INDEX ... 265 ■CONTENTS xi



