SAMS Teach Yourself Ajax in 10 Minutes By Phil Ballard Publisher: Sams Pub Date: April 28, 2006 Print ISBN-10: 0-672-32868-2 Print ISBN-13: 978-0-672-32868-8 Pages: 240 Table of Contents | Index Sams Teach Yourself Ajax in 10 Minutes is a concise introduction to the basics of building Ajax applications and the architecture and operation of these applications You will learn the techniques employed in using Ajax, introducing Ajax and explaining how it may be used to solve realistic user interface problems You will be able to immediately begin building web applications, and will have platform from which to explore more advanced aspects of Ajax SAMS Teach Yourself Ajax in 10 Minutes By Phil Ballard Publisher: Sams Pub Date: April 28, 2006 Print ISBN-10: 0-672-32868-2 Print ISBN-13: 978-0-672-32868-8 Pages: 240 Table of Contents | Index Copyright About the Author Acknowledgments We Want to Hear from You! Reader Services Introduction About This Book What Is Ajax? Who This Book Is For What Do I Need To Use This Book? Conventions Used in This Book Online Resources and Errata Part I: A Refresher on Web Technologies Lesson 1 Anatomy of a Website A Short History of the Web Workings of the World Wide Web Summary Lesson 2 Writing Web Pages in HTML Introducing HTML Elements of an HTML Page A More Advanced HTML Page Some Useful HTML Tags Cascading Style Sheets in Two Minutes Summary Lesson 3 Sending Requests Using HTTP Introducing HTTP The HTTP Request and Response HTML Forms Summary Lesson 4 Client-Side Coding Using JavaScript About JavaScript In at the Deep End Manipulating Data in JavaScript Summary Lesson 5 Server-Side Programming in PHP Introducing PHP Embedding PHP in HTML Pages Variables in PHP Controlling Program Flow Summary Lesson 6 A Brief Introduction to XML Introducing XML XML Basics JavaScript and XML The Document Object Model (DOM) Summary Part II: Introducing Ajax Lesson 7 Anatomy of an Ajax Application The Need for Ajax Introducing Ajax The Constituent Parts of Ajax Putting It All Together Summary Lesson 8 The XMLHTTPRequest Object More About JavaScript Objects Introducing XMLHTTPRequest Creating the XMLHTTPRequest Object Summary Lesson 9 Talking with the Server Sending the Server Request Monitoring Server Status The Callback Function Summary Lesson 10 Using the Returned Data The responseText and responseXML Properties Another Useful JavaScript DOM Property Parsing responseXML Providing User Feedback Summary Lesson 11 Our First Ajax Application Constructing the Ajax Application The HTML Document Adding JavaScript Putting It All Together Summary Part III: More Complex Ajax Technologies Lesson 12 Returning Data as Text Getting More from the responseText Property Summary Lesson 13 AHAHAsynchronous HTML and HTTP Introducing AHAH Creating a Small Library for AHAH Using myAHAHlib.js Summary Lesson 14 Returning Data as XML Adding the "x" to Ajax The responseXML Property ProjectAn RSS Headline Reader Summary Lesson 15 Web Services and the REST Protocol Introduction to Web Services RESTRepresentational State Transfer Using REST in Practice REST and Ajax Summary Lesson 16 Web Services Using SOAP Introducing SOAP (Simple Object Access Protocol) The SOAP Protocol Using Ajax and SOAP Reviewing SOAP and REST Summary Lesson 17 A JavaScript Library for Ajax An Ajax Library Reviewing myAHAHlib.js Implementing Our Library Using the Library Extending the Library Summary Lesson 18 Ajax "Gotchas" Common Ajax Errors The Back Button Bookmarking and Links Telling the User That Something Is Happening Making Ajax Degrade Elegantly Dealing with Search Engine Spiders Pointing Out Active Page Elements Don't Use Ajax Where It's Inappropriate Security Test Code Across Multiple Platforms Ajax Won't Cure a Bad Design Some Programming Gotchas Summary Part IV: Commercial and Open Source Ajax Resources Lesson 19 The prototype.js Toolkit Introducing prototype.js Wrapping XMLHTTPRequestthe Ajax Object Example ProjectStock Price Reader Summary Lesson 20 Using Rico Introducing Rico Rico's Other Interface Tools Summary Lesson 21 Using XOAD Introducing XOAD XOAD HTML Advanced Programming with XOAD Summary Index Copyright SAMS Teach Yourself Ajax in 10 Minutes Copyright © 2006 by Sams Publishing All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Library of Congress Catalog Card Number: 2005934928 Printed in the United States of America First Printing: April 2006 09 08 07 06 4 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Sams Publishing cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied The information provided is on an "as is" basis The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the CD or programs accompanying it Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales For more information, please contact U.S Corporate and Government Sales 1-800-382-3419 corpsales@pearsontechgroup.com For sales outside of the U.S., please contact International Sales international@pearsoned.com ACQUISITIONS EDITOR Linda Harrison DEVELOPMENT EDITOR Damon Jordan MANAGING EDITOR Charlotte Clapp PROJECT EDITOR Seth Kerney COPY EDITOR Geneil Breeze INDEXER Ken Johnson PROOFREADER Leslie Joseph TECHNICAL EDITOR Bill Bercik PUBLISHING COORDINATOR Vanessa Evans MULTIMEDIA DEVELOPER Dan Scherf INTERIOR DESIGNER Gary Adair COVER DESIGNER Aren Howell PAGE LAYOUT TnT Design Dedication To Sue, for her endless patience and support during the writing of this bookand at all other times, too About the Author Phil Ballard graduated in 1980 with an honors degree in electronics from the University of Leeds, England Following an early career as a research scientist with a major multinational, Phil spent a few years in commercial and managerial roles within the high technology sector, later working full time as a software engineering consultant Operating as "The Mouse Whisperer" (http://www.mousewhisperer.co.uk), Phil has spent recent years involved solely in website and intranet design and development for an international portfolio of clients Another of his websites, http://www.crackajax.net, is home to an active and fast-growing Ajax programming community Phil is currently based in southeast England In his spare time, he still plays bass guitar in rock bands, despite being easily old enough to know better quotes, escaping variables XOAD PHP interpreter, @ characters pixels, defining platform code tests pop-ups POST requests 2nd HTTP requests 2nd JavaScript libraries message bodies troubleshooting previousSibling property programmer's editors, HTML prologs (XML) prototype.js $() function $F() function Ajax objects download website Form objects getElements() method Rico elements AjaxEngine instances callRICO() function cinematic effects drag-and-drop multiple page element updates usage example web applications, adding to serialize() method Stock Price Reader build example Try.these() function web applications, adding to PUT requests Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] query strings, GET requests quotes, escaping in PHP scripts Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] readyState property 2nd reason phrases (HTTP responses) registerDraggable method registerDropZone method RemoveChild method requests (HTTP) 2nd 3rd responseAHAH() functions responseAjax() function 2nd responses (HTTP) responseText property 2nd character strings formatted data HTML manipulation methods list myAHAHlib.js myAJAXlib.js null values returned text using in page elements values, displaying/manipulating responseXML property 2nd 3rd REST (Representational State Transfer) Amazon.com REST API articles, uploading DELETE requests example of GET requests POST requests principles of PUT requests SOAP versus stateless operations Rico elements AjaxEngine instances callRICO() function cinematic effects drag-and-drop multiple page element updates usage example web applications, adding to RSS feeds RSS headline readers runServer() function Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] script tags (HTML) search engine spiders, troubleshooting security troubleshooting XMLHTTPRequest objects send method, XMLHTTPRequest object send(content) method serialize() method, prototype.js server requests basic application creation example browser caches callback functions GET requests in progress notifications readyState property sending, XMLHTTPRequest objects status, monitoring timestamps user feedback server resources (HTTP requests) server responses getElementsByTagName() method in progress notifications responseText property responseXML property user feedback server-side programming, defining server-side scripts setRequestHeader method seville.html document example sizeof() function SOAP (Simple Object Access Protocol) spiders, troubleshooting split() method src attribute (image tags) status codes table (HTTP responses) status lines (HTTP responses) status property 2nd statusText property 2nd Stock Price Reader build example style sheets, setting rules substring method, responseText property Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] table tags (HTML) tagname properties (DOM) tags HTML XML testpage.html document example text editors, HTML text properties (DOM) text-based web browsers timestamps, server requests title tags (HTML) toLowerCase() method, responseText property toUpperCase() method, responseText property troubleshooting application design Back button codes bookmarks browser caches code, platform tests GET requests links page design Permission Denied errors POST requests security spiders unsupported browsers user feedback Try.these() function Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] unsupported browsers, troubleshooting URL (Uniform Resource Locators), RSS headline readers user feedback basic application creation example JavaScript libraries server requests troubleshooting Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] valid XML documents, defining variables JavaScript PHP Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] W3C validator website W3C website Web (World Wide), development of web browsers availability of defining graphical web browsers HTML documents, loading text-based web browsers unsupported browser web server interaction web pages defining elements, adding via responseXML property HTTP requests id values web servers web services example of REST Amazon.com REST API articles, uploading DELETE requests example of GET requests lists of available articles, reading particular articles, retrieving POST requests principles of PUT requests SOAP versus stateless operations SOAP while loops word processors, HTML Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] XML (eXtensible Markup Language) ATTLIST declarations comments, displaying data, retrieving DOCTYPE declarations document elements ELEMENT declarations HTML, similarities to JavaScript prologs responseXML property RSS headline readers server responses tags valid documents, defining XMLHTTPRequest objects basic application creation example callAjax() function instances, creating JavaScript libraries methods properties responseAjax() function security server requests 2nd server-side scripts uses of XOAD (XMLHTTP Object-oriented Application Development) XOAD Controls class XOAD HTML XOAD HTML:getElementByID() method XOAD HTML:getElementByTagName() method XSLT .. .SAMS Teach Yourself Ajax in 10 Minutes By Phil Ballard Publisher: Sams Pub Date: April 28, 2006 Print ISBN -10: 0-672-32868-2 Print ISBN- 13: 978-0-672-32868-8... Using Rico Introducing Rico Rico's Other Interface Tools Summary Lesson 21 Using XOAD Introducing XOAD XOAD HTML Advanced Programming with XOAD Summary Index Copyright SAMS Teach Yourself Ajax in 10 Minutes. .. About This Book Part of the Sams Publishing Teach Yourself in 10 Minutes series, this book aims to teach the basics of building Ajax applications for the Internet Divided into bite-sized lessons, each designed