Thông tin tài liệu
www.it-ebooks.info
Professional
Ajax
2
nd
Edition
Nicholas C. Zakas
Jeremy McPeak
Joe Fawcett
01_109496 ffirs.qxd 2/5/07 6:41 PM Page i
www.it-ebooks.info
01_109496 ffirs.qxd 2/5/07 6:41 PM Page i
www.it-ebooks.info
Professional
Ajax
2
nd
Edition
Nicholas C. Zakas
Jeremy McPeak
Joe Fawcett
01_109496 ffirs.qxd 2/5/07 6:41 PM Page i
www.it-ebooks.info
Professional Ajax, 2nd Edition
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-10949-6
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data:˙
Zakas, Nicholas C.
Professional Ajax / Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett. 2nd ed.
p. cm.
Includes index.
ISBN-13: 978-0-470-10949-6 (paper/website)
ISBN-10: 0-470-10949-1 (paper/website)
1. Ajax (Web site development technology) 2. Web sites Design Computer programs. 3. JavaScript (Computer pro-
gram language) 4. Asynchronous transfer mode. 5. World Wide Web. I. McPeak, Jeremy, 1979- II. Fawcett, Joe, 1962-
III. Title.
TK5105.8885.A52Z35 2007
005.13'3 dc22
2006103094
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317)
572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRE-
SENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED
OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED
HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING
THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFES-
SIONAL SERVICES. IF PROFESSIONALASSISTANCE IS REQUIRED, THE SERVICES OF ACOMPETENT PROFES-
SIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE
FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO
IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT
MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR
WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE
THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN
WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Department within the
United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other
countries, and may not be used without written permission. All other trademarks are the property of their respective
owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be avail-
able in electronic books.
01_109496 ffirs.qxd 2/5/07 6:41 PM Page ii
www.it-ebooks.info
To mom, dad, Greg, Yiayia, and the rest of my family and friends who have
supported me throughout my cross-country move.
—Nicholas C. Zakas
To the love of my life, Starla. Thank you for your love, patience, and
encouragement.
—Jeremy McPeak
To my parents, Sheila and William, who instilled in me a love of reading.
Thank you!
—Joe Fawcett
01_109496 ffirs.qxd 2/5/07 6:41 PM Page iii
www.it-ebooks.info
About the Authors
Nicholas C. Zakas has a BS in Computer Science from Merrimack College and an MBA from Endicott
College. He is the author of Professional JavaScript for Web Developers (Wiley 2005) as well as several
online articles. Nicholas works for Yahoo! as a frontend engineer and has worked in web development
for more than 6 years, during which time he has helped develop web solutions in use at some of the
largest companies in the world. Nicholas can be reached through his web site at
www.nczonline.net.
Jeremy McPeak began tinkering with web development as a hobby in 1998. Currently working in the IT
department of a school district, Jeremy has experience developing web solutions with JavaScript, PHP,
and C#. He has written several online articles covering topics such as XSLT, WebForms, and C#. He is
also co-author of Beginning JavaScript, 3rd Edition (Wiley 2007). Jeremy can be reached through his web
site at
www.wdonline.com.
Joe Fawcett started programming in the 1970s and briefly worked in IT upon leaving full-time educa-
tion. He then pursued a more checkered career before returning to software development in 1994. In
2003 he was awarded the title of Microsoft Most Valuable Professional in XML for community contribu-
tions and technical expertise. He currently works in London as a developer for FTC Kaplan, a leading
international provider of accountancy and business training, where he specializes in systems integration.
01_109496 ffirs.qxd 2/5/07 6:41 PM Page iv
www.it-ebooks.info
Credits
Senior Acquisitions Editor
Jim Minatel
Senior Development Editor
Kevin Kent
Technical Editor
Alexei Gorkov
Production Editor
Angela Smith
Copy Editor
Jeri Freedman
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Graphics and Production Specialists
Sean Decker
Jennifer Mayberry
Amanda Spagnuolo
Alicia B. South
Quality Control Technician
Rob Springer
Project Coordinator
Bill Ramsey
Proofreading
Christopher Jones
Indexing
Johnna VanHoose Dinse
Anniversary Logo Design
Richard Pacifico
01_109496 ffirs.qxd 2/5/07 6:41 PM Page v
www.it-ebooks.info
Acknowledgments
It takes many people to create a book such as this, and as such, we’d like to thank some people for their
contributions to this work.
First and foremost, thanks to everyone at Wiley for their support: to Jim Minatel for starting the process
once again, and Kevin Kent for putting up with all of the last-minute changes and course diversions
throughout the process. Also, a thanks to our technical editor, Alexei Gorkov, for doing a fantastic job
keeping us honest.
Last, a big thanks to those who provided feedback pre-publication including Peter Frueh, Adam Moore,
Jenny Han, Matt Sweeney, Tyson Guskiken, Steve Carlson, and especially Hedger Wang, who suggested
adding the chapter on request management.
01_109496 ffirs.qxd 2/5/07 6:41 PM Page vi
www.it-ebooks.info
Contents
Introduction xv
Chapter 1: What Is Ajax? 1
Ajax Is Born 2
The Evolution of the Web 2
JavaScript 2
Frames 3
The Hidden Frame Technique 3
Dynamic HTML and the DOM 3
Iframes 4
XMLHttp 4
The Real Ajax 5
Ajax Principles 6
Technologies behind Ajax 6
Who Is Using Ajax? 7
Google Suggest 7
Gmail 8
Google Maps 9
A9 10
Yahoo! News 11
Bitflux Blog 12
Confusion and Controversy 13
Ajax and Web 2.0 14
Summary 15
Chapter 2: Ajax Basics 17
HTTP Primer 17
HTTP Requests 18
HTTP Responses 20
Ajax Communication Techniques 21
The Hidden Frame Technique 21
XMLHttp Requests (XHR) 37
Ajax with Images 50
Dynamic Script Loading 59
Cache Control 63
Summary 63
02_109496 ftoc.qxd 2/5/07 6:46 PM Page vii
www.it-ebooks.info
[...]... 416 Using DWR DWR Example More about dwr.xml Summary of DWR 416 419 424 427 Ajax. NET Professional 427 Using Ajax. NET Professional Type Conversion Session Access Ajax. NET Professional Example Summary of Ajax. NET Professional Summary 427 429 430 431 436 436 Chapter 14: ASP.NET AJAX Extensions (Atlas) Requirements and Setup The AJAX Client Library 437 438 438 Accessing the Client Tools with ASP NET Accessing... 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. .. 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... 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... 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... pressing Enter The LiveSearch Ajax functionality is just an enhancement to the overall site and isn’t required to search 12 www.it-ebooks.info What Is Ajax? Figure 1-7 Confusion and Controversy Despite the popularity of the term Ajax, it has been met with its fair share of dissenters and controversy Some believe that Ajax is an aberration of what the Web was moving toward before Ajax entered the picture... Contents The $.post() Method POST Example The load() Method The $ .ajax( ) Method The ajaxStart() and ajaxStop() Methods Limitations Summary 120 120 122 123 124 124 125 Chapter 5: Request Management Priority Queues The RequestManager Object Request Description Objects Queuing Requests Sending Requests Cancelling Requests Age-Based Promotion Handling Ajax Patterns Using RequestManager Summary 127 127 131 132... Summary 97 Chapter 4: Ajax Libraries 99 The Yahoo! Connection Manager 99 Setup Basic Requests The Callback Object Monitoring and Managing Requests Form Interaction File Uploads GET Example POST Example Additional Features Limitations 99 100 100 104 104 105 106 107 108 108 Prototype 109 The Ajax. Request Object The Options Object GET Example POST Example The Ajax. Updater Object The Ajax. Responders Object... server, the Ajax model provides an intermediate layer — what Garrett calls an Ajax engine — to handle this communication An Ajax engine is really just a JavaScript object or function that is called whenever information needs to be requested from the server Instead of the traditional model of providing a link to another resource (such as another web page), each link makes a call to the Ajax engine,... between the traditional and Ajax web application models Traditional Web Application Model Web Browser HTML, Images, CSS, JavaScript Data HTTP Request Query/Data Request Database Web Server Ajax Web Application Model Web Browser HTML, CSS Data Data HTTP Request Query/Data Request Ajax Engine User Interface JavaScript Call Database Web Server Figure 1-1 5 www.it-ebooks.info Chapter 1 Ajax Principles As a new . 427
Ajax. NET Professional 427
Using Ajax. NET Professional 427
Type Conversion 429
Session Access 430
Ajax. NET Professional Example 431
Summary of Ajax. NET. and the DOM 3
Iframes 4
XMLHttp 4
The Real Ajax 5
Ajax Principles 6
Technologies behind Ajax 6
Who Is Using Ajax? 7
Google Suggest 7
Gmail 8
Google Maps
Ngày đăng: 06/03/2014, 06:20
Xem thêm: Professional Ajax pdf