Beta
Book
Agile publishing for agile developers
The book you’re reading is still under development. As an experiment,
we’re releasing this copy well before we normally would. That way
you’ll be able to get this content a couple of months before it’s avail-
able in finished form, and we’ll get feedback to make the book even
better. The idea is that everyone wins!
Be warned. The book has not had a full technical edit, so it will con-
tain errors. It has not been copyedited, so it will be full of typos.
And there’s been no effort spent doing layout, so you’ll find bad page
breaks, over-long lines, incorrect hyphenations, and all the other ugly
things that you wouldn’t expect to see in a finished book. We can’t
be held liable if you use this book to try to create a spiffy application
and you somehow end up with a strangely shaped farm implement
instead. Despite all this, we think you’ll enjoy it!
Throughout this process you’ll be able to download updated PDFs
from
http://books.pragprog.com/titles/ajax/reorder.
When the book is finally ready, you’ll get the final version (and
subsequent updates) from the same address. In the meantime,
we’d appreciate you sending us your feedback on this book at
http://books.pragprog.com/titles/ajax/errata.
Thank you for taking part in this experiment.
Dave Thomas
Pragmatic Ajax
AWeb2.0Primer
Justin Gehtland
Ben Galbraith
Dion Almaer
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
Bookshelf
Pragmatic
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The
Pragmatic Programmers, LLC was aware of a trademark claim, the designations have
been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g
device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragmaticprogrammer.com
Copyright
©
2005 The Pragmatic Programmers LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmit-
ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or
otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN 0-9766940-8-5
Printed on acid-free paper with 85% recycled, 30% post-consumer content.
First printing, October 2005
Version: 2005-10-26
Contents
1 Building Rich Internet Applications with Ajax 1
1.1 A Tale in Three Acts ..................... 2
1.2 Google Maps: The Missing Spark ............. 4
1.3 What is Ajax? ......................... 5
1.4 Whither Now? ......................... 8
2AjaxInAction 9
2.1 Ajaxifying a Web Application ................ 9
2.2 Ajax to the Rescue ...................... 10
2.3 The Grubby Details ..................... 17
2.4 Wrapping Up ......................... 20
3 Ajax Explained 21
3.1 A Review of Client-side JavaScript ............. 22
3.2 Manipulating the Web Page ................. 29
3.3 Retrieving Data ........................ 34
3.4 Summary ........................... 36
4 Creating Google Maps 38
4.1 Rocket Scientists? ...................... 38
4.2 Your Own Google Maps ................... 39
4.3 Creating Ajaxian Maps ................... 45
4.4 Conclusion .......................... 73
5 Ajax Frameworks 74
5.1 Frameworks, Toolkits, and Libraries ........... 74
5.2 Remoting with the Dojo Toolkit ............... 79
5.3 Remoting with the Prototype library ............ 86
5.4 Wrapping Up ......................... 88