1. Trang chủ
  2. » Công Nghệ Thông Tin

Prentice hall AJAX construction kit building plug and play AJAX applications jul 2007 ISBN 0132350084

569 70 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 569
Dung lượng 5,15 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The CD includes a bootable Ubuntu Linuxvariant operating system that includes the Apache Web serverand all of the sample Ajax applications covered in the book.Perhaps more interesting is

Trang 1

Negus Live Linux Series Ajax Construction Kit: Building Plug-and-Play Ajax Applications

by Michael Morrison

Publisher: Prentice Hall Pub Date: June 29, 2007 Print ISBN-10: 0-13-235008-4 Print ISBN-13: 978-0-13-235008-2 Pages: 312

successful Ajax Construction Kit lets you put Ajax to work

right now, even if you've never written a script! Just learn a few

essentials, check out a few examples, then run the live CD anddiscover all the plug-and-play code you need to hit the ground

running Ajax Construction Kit's built-in applications work

right out of the box And with easy guidance from Michael

Morrison, you'll gradually deepen your understanding learnhow to customize, extend, and reuse these applications and

Trang 2

Negus Live Linux Series

Your Practical, Hands-On Guides to Getting Real Results with

Trang 3

Add the free software and examples from the book's CD to yourWindows, Mac OS X, or Linux system to follow along with theprojects described in the book Or boot the CD directly to use acomplete, prepackaged set of free software tools to play,

display, and modify those projects Start as a novice, by tryingout examples and finish with professional Ajax-enabled Webcontent!

SERIES EDITOR CHRISTOPHER NEGUS is the bestselling

author of the Red Hat Linux Bible series, Linux Toys series, and this series's flagship title, Linux Live CDs.

8 A Killer Interface for Image Viewing 159

9 Presenting Information with Slick Popups 171

10 Forecasting the Weather with Ajax 189

Trang 4

12 Adding an Ajax-Powered Rating System to Your Site231

Part III Appendices

Appendix A The Past, Present, and Future of Ajax 257Appendix B A Quick and Dirty XMLHttpRequest Reference261

Appendix C Using the Live Linux CD 271

Trang 5

Negus Live Linux Series Ajax Construction Kit: Building Plug-and-Play Ajax Applications

by Michael Morrison

Publisher: Prentice Hall

Pub Date: June 29, 2007

Print ISBN-10: 0-13-235008-4 Print ISBN-13: 978-0-13-235008-2 Pages: 312

Trang 6

The Challenge: Displaying Selected Stock InformationThe Design: Designing a Stock Picker

Trang 7

Testing Forecaster

Giving Forecaster an Extreme Ajax Makeover

Trang 8

Events

Appendix C Using the Live Linux CD

Trang 10

Many of the designations used by manufacturers and sellers todistinguish their products are claimed as trademarks Wherethose designations appear in this book, and the publisher wasaware of a trademark claim, the designations have been printedwith initial capital letters or in all capitals

The author and publisher have taken care in the preparation ofthis book, but make no expressed or implied warranty of anykind and assume no responsibility for errors or omissions Noliability is assumed for incidental or consequential damages inconnection with or arising out of the use of the information orprograms contained herein

The publisher offers excellent discounts on this book when

ordered in quantity for bulk purchases or special sales, whichmay include electronic versions and/or custom covers and

content particular to your business, training goals, marketingfocus, and branding interests For more information, please

Trang 13

guided me through the construction of our home while I attempted to juggle a writing career and far too many sports and hobbies.

Trang 14

Your practical, hands-on guides to getting real results with free software

Add the free software and examples from the book's CD to yourWindows, Mac OS X, or Linux system to follow along with theprojects described in the book Or boot the CD directly to use acomplete, prepackaged set of free software tools to play,

display, and modify those projects Start as a novice, by tryingout examples and finish with professional Ajax-enabled Webcontent!

Overseeing the series is Christopher Negus, bestselling author

of the Red Hat Linux Bible series, Linux Toys series, and the

signature book for this series, Live Linux CDs.

Trang 15

I'd like to thank Debra Williams Cauley and the good folks atPrentice Hall for making this project a reality, as well as ChrisNegus for being excited and supportive from the get-go

A huge thanks also goes to my good friends Stephen Tallent andFletcher Moore, who came through mightily in the midnight

tech-support department, not to mention passing along lots ofgood ideas and sharing their time generously

And lastly, my wife deserves the biggest thanks of all for simplybeing the coolest person on the planet, at least in one nerd

writer's humble opinion

Trang 16

Michael Morrison is a writer, developer, toy inventor, and

author of a variety of books covering topics such as Java, Webscripting, game development, and mobile devices Some of

Michael's notable writing projects include JavaScript Bible, 6th

Edition (Wiley, 2006), Teach Yourself HTML and CSS in 24

Hours, 7th Edition (Sams Publishing, 2005), Beginning Mobile Phone Game Programming (Sams Publishing, 2004), and Java Unleashed (Sams Publishing, 1997) Michael is the instructor of

several Web-based courses, including DigitalThink's Introduction

to Java 2 series, JavaBeans for Programmers series, and Win32Programming series (www.digitalthink.com)

In addition to his primary profession as a writer and technicalconsultant, Michael is the founder of Stalefish Labs

(www.stalefishlabs.com), an entertainment company

specializing in games, toys, and interactive media When notglued to his computer, skateboarding, playing hockey, or

watching movies with his wife, Masheed, Michael enjoys

hanging out by his koi pond

Trang 17

This whole book idea started as a bet I had with my editor that

we couldn't pick two random techie topics and tie them together

in a book Two darts flew through the air and the topics "Ajax"and "live CDs" ended up being the result This book could'vejust as easily been about Blu-ray on Rails or iPod design

patterns So it's just dumb luck that you're picking up a book onAjax and live CDs

And if you believe that, maybe I can interest you in helping

fund this startup company I've been thinking about launching!The truth is, Ajax and live CDs are surprisingly good bedfellows

in that live CDs provide the perfect environment for buildingand testing Ajax applications The whole idea of a "live CD" isthat it includes a complete operating system on a single CD.Along with a complete operating system, you get to include anyapplications you want, such as a Web server that can serve upAjax applications

One thing that is unique about Ajax applications as compared topurely client-side applications developed solely in JavaScript isthat they require something to happen on the server In otherwords, the very premise of Ajax is communication between aclient and a server This means you not only need a server, butyou need a server that you have a bit of control over At thevery least, you need the ability to quickly install and test

server-side scripts that will handle the server-side processingfor your Ajax applications Live CDs fit the bill nicely in terms ofgiving you an unbelievably customizable platform for building,testing, and hosting Ajax applications

As cool as live CDs can be, I have to be honest and say that thisbook is 95% about Ajax The live CD facet of this book is

primarily a convenience due to the fact that Ajax applicationsare more demanding of their environment than pure client

applications

Trang 18

Dynamically load e-book chapters for a Web-based bookreader (Chapter 3)

Instantly select and view live stock quotes (Chapter 4)

Turn any Web page into a news aggregator that

understands RSS news feeds (Chapter 5)

Add auto-complete functionality to your Web site (Chapter6)

Validate form data and look up location data in real time(Chapter 7)

Create a "Web 2.0" image viewer to modernize the wayyour pages handle images (Chapter 8)

Use informational popup windows to dynamically displaysmall nuggets of content (Chapter 9)

Add a live weather condition popup window to any link

(Chapter 10)

Calculate shipping charges on the fly with a U.S PostalService Ajax request (Chapter 11)

Incorporate an animated five-star rating system into yourWeb pages (Chapter 12)

These are the kinds of dynamic applications that Ajax makespossible More importantly, this book uses a construction kitapproach to guiding you through adding these features to Ajaxapplications Although you will ultimately learn a lot about Ajax

as you explore the many examples presented throughout thisbook, the focus of the book is not on teaching you Ajax Thefocus is on showing you how to do cool things with Ajax

Sometimes this requires you to learn something entirely new;

Trang 19

point is that this book is about doing things.

In my opinion, doing is learning, so you'll ultimately leave thisbook with a much more thorough understanding of Ajax thanwhen you started But more importantly, you'll leave it with

your own set of Ajax building blocks that you can take with youand apply to your own projects

The Audience for This Book

I won't lie to you—this book by its very nature has to delve intoJavaScript and PHP on a regular basis as the various Ajax

examples are presented However, the original goal of the bookwas for it to be approachable by anyone with knowledge of

HTML and CSS (Cascading Style Sheets), and not necessarily abackground in scripting, either client (JavaScript) or server

(PHP) I'm not entirely sure that was a realistic goal, but it

served me well in trying extremely hard to present enough Ajaxcoverage for the examples to make sense but not so much toscare away scripting newcomers

All that being said, you absolutely must know a thing or twoabout HTML to tackle this book CSS isn't quite as critical, but itdoes come up from time to time, so you might as well consider

a basic knowledge of CSS a prerequisite From there, it wouldserve you well to know something about JavaScript because it isthe basis of Ajax However, I believe you can duck and weaveyour way through the JavaScript code in this book with a limitedknowledge of Web scripting, and still leave with a toolbox full ofAjax goodies that can be readily reused The PHP code that

pops up throughout the book is very simple, and I explain

exactly what's going on, so you can definitely get by withoutknowing anything about PHP

Trang 20

This whole book idea started as a bet I had with my editor that

we couldn't pick two random techie topics and tie them together

in a book Two darts flew through the air and the topics "Ajax"and "live CDs" ended up being the result This book could'vejust as easily been about Blu-ray on Rails or iPod design

patterns So it's just dumb luck that you're picking up a book onAjax and live CDs

And if you believe that, maybe I can interest you in helping

fund this startup company I've been thinking about launching!The truth is, Ajax and live CDs are surprisingly good bedfellows

in that live CDs provide the perfect environment for buildingand testing Ajax applications The whole idea of a "live CD" isthat it includes a complete operating system on a single CD.Along with a complete operating system, you get to include anyapplications you want, such as a Web server that can serve upAjax applications

One thing that is unique about Ajax applications as compared topurely client-side applications developed solely in JavaScript isthat they require something to happen on the server In otherwords, the very premise of Ajax is communication between aclient and a server This means you not only need a server, butyou need a server that you have a bit of control over At thevery least, you need the ability to quickly install and test

server-side scripts that will handle the server-side processingfor your Ajax applications Live CDs fit the bill nicely in terms ofgiving you an unbelievably customizable platform for building,testing, and hosting Ajax applications

As cool as live CDs can be, I have to be honest and say that thisbook is 95% about Ajax The live CD facet of this book is

primarily a convenience due to the fact that Ajax applicationsare more demanding of their environment than pure client

applications

Trang 21

Dynamically load e-book chapters for a Web-based bookreader (Chapter 3)

Instantly select and view live stock quotes (Chapter 4)

Turn any Web page into a news aggregator that

understands RSS news feeds (Chapter 5)

Add auto-complete functionality to your Web site (Chapter6)

Validate form data and look up location data in real time(Chapter 7)

Create a "Web 2.0" image viewer to modernize the wayyour pages handle images (Chapter 8)

Use informational popup windows to dynamically displaysmall nuggets of content (Chapter 9)

Add a live weather condition popup window to any link

(Chapter 10)

Calculate shipping charges on the fly with a U.S PostalService Ajax request (Chapter 11)

Incorporate an animated five-star rating system into yourWeb pages (Chapter 12)

These are the kinds of dynamic applications that Ajax makespossible More importantly, this book uses a construction kitapproach to guiding you through adding these features to Ajaxapplications Although you will ultimately learn a lot about Ajax

as you explore the many examples presented throughout thisbook, the focus of the book is not on teaching you Ajax Thefocus is on showing you how to do cool things with Ajax

Sometimes this requires you to learn something entirely new;

Trang 22

point is that this book is about doing things.

In my opinion, doing is learning, so you'll ultimately leave thisbook with a much more thorough understanding of Ajax thanwhen you started But more importantly, you'll leave it with

your own set of Ajax building blocks that you can take with youand apply to your own projects

The Audience for This Book

I won't lie to you—this book by its very nature has to delve intoJavaScript and PHP on a regular basis as the various Ajax

examples are presented However, the original goal of the bookwas for it to be approachable by anyone with knowledge of

HTML and CSS (Cascading Style Sheets), and not necessarily abackground in scripting, either client (JavaScript) or server

(PHP) I'm not entirely sure that was a realistic goal, but it

served me well in trying extremely hard to present enough Ajaxcoverage for the examples to make sense but not so much toscare away scripting newcomers

All that being said, you absolutely must know a thing or twoabout HTML to tackle this book CSS isn't quite as critical, but itdoes come up from time to time, so you might as well consider

a basic knowledge of CSS a prerequisite From there, it wouldserve you well to know something about JavaScript because it isthe basis of Ajax However, I believe you can duck and weaveyour way through the JavaScript code in this book with a limitedknowledge of Web scripting, and still leave with a toolbox full ofAjax goodies that can be readily reused The PHP code that

pops up throughout the book is very simple, and I explain

exactly what's going on, so you can definitely get by withoutknowing anything about PHP

Trang 23

Although this book follows the charter of the Negus Live LinuxSeries to provide hands-on experience quickly, the organization

of the book is slightly unconventional The book is divided intothree parts:

Part I , "Ajax Boot Camp"— This part of the book wastes

no time laying just enough groundwork so that you aren'toverwhelmed by the intensity of the sample Ajax

world Ajax applications and get acquainted with the AjaxToolkit that ships on the accompanying CD-ROM You'll

applications to come You explore several commercial real-leave this part of the book revved up to see Ajax in action

Part II , "Building Real-World Ajax Applications"— This

part of the book, which constitutes the remainder of thebook, is focused entirely on using Ajax to solve real-worldproblems From dynamically resolving a ZIP code into a

city/state for a data entry form, to injecting an interactivefive-star rating system into a page, this part of the bookwastes no time and takes no prisoners Don't get me

wrong, it's still a fun read, but don't expect a bunch of

tutorial talk or an essay on the history of Ajax This part ofthe book in particular is all about doing!

Part III , "Appendices"— This part provides additional

information you may find helpful Appendix A, "The Past,Present, and Future of Ajax," paints a picture of where Ajaxcame from and where it's headed This is in no way critical

to understanding how to add Ajax-powered features to yourWeb pages, but it does add some perspective to the buzzswirling around Ajax these days Appendix B, "A Quick andDirty XMLHttpRequest Reference" is exactly that—a

reference for the JavaScript object that serves as the core

of Ajax This object is actually hidden for the most part

throughout the book thanks to the Ajax Toolkit, but if youever want to dig deeper into my code and modify the Toolkit

Trang 24

object

Finally, Appendix C, "Using the Live Linux CD," is arguablythe handiest of all the appendixes because it explains

exactly how to use the live Linux CD that comes with thebook Don't worry a bit if you've never used or even heard

of a live CD, and don't think you need to be a Linux expert

or even have Linux installed Appendix C addresses the role

of the live CD and guides you through how to use it for yourparticular hardware setup

Trang 25

The CD-ROM that comes with this book is where live CDs enterinto the Ajax picture The CD includes a bootable Ubuntu (Linuxvariant) operating system that includes the Apache Web serverand all of the sample Ajax applications covered in the book.Perhaps more interesting is the fact that you can run the

to explore the example applications, check out Appendix C,

"Using the Live Linux CD."

Trang 26

Live Linux CDs are available to run on a range of computer

hardware, such as standard PC architecture (i386), PowerPC(PPC), and 64-bit AMD (AMD64) I recommend a minimum of aPentium III-class PC and at least 128MB of RAM for running the

CD that comes with the book As for hard-disk requirements,you don't even need to have a hard disk in the computer to runthe live CD You might consider getting a USB flash drive (alsosometimes called a pen drive, thumb drive, or memory stick).Because live CDs are typically run from read-only media, USBflash drives are good to keep handy in the event that an

application needs to write data, as is the case in Chapter 12,

"Adding an Ajax-Powered Rating System to Your Site." And

again, please refer to Appendix C for detailed instructions onhow to use the live CD

Trang 27

Chapter 1 Ajax and a Brave New World WideWeb

Chapter 2 Inside an Ajax Application

Trang 28

Chapter 1 Ajax and a Brave New World Wide Web

Ajax in Cartoons

Ajax Corporation is a fictional corporationused by Metro-Goldwyn-Mayer (MGM) as aparody of Warner Brothers' Acme

Corporation, which is featured prominently

in Road Runner cartoons The Ajax Corporation is primarily referenced in Tom

and Jerry cartoons.

So I'm waiting for my order at a fast food restaurant the otherday, and I started to question why the word "fast" had any

business in the description of this particular place I was eager

to have a seat and flip through a magazine, not loiter in a

crowded lobby waiting for my "fast" food This situation got methinking about Ajax and how it improves the overall Web

experience Yes, in an arguably twisted way, it's possible to look

at Ajax through the greasy lens of a hamburger wrapper And injust a moment you'll see how

Although it isn't strictly considered an acronym, the name Ajaxultimately derives from Asynchronous JavaScript and XML Thekey benefits to Ajax are that it allows you to receive small

chunks of data over a Web connection asynchronously, meaningyou don't have to wait around for it, and in most cases you canavoid a full Web page reload The real trick to using Ajax

effectively is to get your brain wrapped around what it can do,which is far more important than what it is or why people seem

so enamored by it Ajax is one of those truly rare Web

innovations whose benefits are immediately understood onceyou see it used in the proper context And sort of like the

popular 3M commercials you sometimes see on television, you

Trang 29

This chapter starts you off with a healthy dose of Ajax realism,with a clear focus on what types of problems it aims to solveand why that matters to you Yes, I also get around to

explaining what it is and why people are enamored by it, butthat's just icing on the cake

Dining with Ajax

Getting back to the fast food analogy in the opener, the

scenario is a crowded fast food restaurant where you have tostand around waiting for your food before you can sit down andget comfortable Contrast this fast food dining experience with afull-service restaurant where your meal is delivered to your

table after you've already sat down and ordered There is a

considerable luxury in being seated at a table going about yourbusiness while someone is busy working away in the kitchenpreparing the meal In the fast food alternative, you must standaround waiting for your food before you can take a seat and getcomfortable, assuming you consider fast food seating

comforting The point I'm getting at is that with the fast foodapproach, the time it takes to prepare your food is time out ofyour pocket because your dining experience is on hold until thefood is ready With a sit-down dinner, you're able to enjoy adrink, munch on an appetizer, and read a magazine, or talk it

up with your dining companion while you wait These are verydifferent experiences, as illustrated in Figure 1.1

Figure 1.1 The time it takes to prepare food goes relatively unnoticed in a full-service dinner because you

are free to enjoy the dining experience.

Trang 30

technique that offers to upgrade your Web pages to a sit-downdining experience Traditional Web applications force you to waitwhile data is searched or otherwise processed on the server.Not so with Ajax An Ajax Web application goes off and

performs its data processing in the background, leaving you tocontinue to interact with the Web page in the meantime Thismay seem like a subtle distinction, but it is not Just ask

yourself, would you rather stand in line at a not-so-fast-foodrestaurant or relax at a cozy table in a sit-down restaurant?

Note

One small problem with my restaurantanalogy for Ajax is that it implies that AjaxWeb applications are somehow slower thantraditional Web applications This is not thecase Ajax applications are no faster orslower in terms of raw data processing Infact, they often give the impression ofbeing faster because processing is typically

Trang 31

going on in the background when you don'teven realize it.

Trang 32

Chapter 1 Ajax and a Brave New World WideWeb

Chapter 2 Inside an Ajax Application

Trang 33

Chapter 1 Ajax and a Brave New World Wide Web

Ajax in Cartoons

Ajax Corporation is a fictional corporationused by Metro-Goldwyn-Mayer (MGM) as aparody of Warner Brothers' Acme

Corporation, which is featured prominently

in Road Runner cartoons The Ajax Corporation is primarily referenced in Tom

and Jerry cartoons.

So I'm waiting for my order at a fast food restaurant the otherday, and I started to question why the word "fast" had any

business in the description of this particular place I was eager

to have a seat and flip through a magazine, not loiter in a

crowded lobby waiting for my "fast" food This situation got methinking about Ajax and how it improves the overall Web

experience Yes, in an arguably twisted way, it's possible to look

at Ajax through the greasy lens of a hamburger wrapper And injust a moment you'll see how

Although it isn't strictly considered an acronym, the name Ajaxultimately derives from Asynchronous JavaScript and XML Thekey benefits to Ajax are that it allows you to receive small

chunks of data over a Web connection asynchronously, meaningyou don't have to wait around for it, and in most cases you canavoid a full Web page reload The real trick to using Ajax

effectively is to get your brain wrapped around what it can do,which is far more important than what it is or why people seem

so enamored by it Ajax is one of those truly rare Web

innovations whose benefits are immediately understood onceyou see it used in the proper context And sort of like the

popular 3M commercials you sometimes see on television, you

Trang 34

This chapter starts you off with a healthy dose of Ajax realism,with a clear focus on what types of problems it aims to solveand why that matters to you Yes, I also get around to

explaining what it is and why people are enamored by it, butthat's just icing on the cake

Dining with Ajax

Getting back to the fast food analogy in the opener, the

scenario is a crowded fast food restaurant where you have tostand around waiting for your food before you can sit down andget comfortable Contrast this fast food dining experience with afull-service restaurant where your meal is delivered to your

table after you've already sat down and ordered There is a

considerable luxury in being seated at a table going about yourbusiness while someone is busy working away in the kitchenpreparing the meal In the fast food alternative, you must standaround waiting for your food before you can take a seat and getcomfortable, assuming you consider fast food seating

comforting The point I'm getting at is that with the fast foodapproach, the time it takes to prepare your food is time out ofyour pocket because your dining experience is on hold until thefood is ready With a sit-down dinner, you're able to enjoy adrink, munch on an appetizer, and read a magazine, or talk it

up with your dining companion while you wait These are verydifferent experiences, as illustrated in Figure 1.1

Figure 1.1 The time it takes to prepare food goes relatively unnoticed in a full-service dinner because you

are free to enjoy the dining experience.

Trang 35

technique that offers to upgrade your Web pages to a sit-downdining experience Traditional Web applications force you to waitwhile data is searched or otherwise processed on the server.Not so with Ajax An Ajax Web application goes off and

performs its data processing in the background, leaving you tocontinue to interact with the Web page in the meantime Thismay seem like a subtle distinction, but it is not Just ask

yourself, would you rather stand in line at a not-so-fast-foodrestaurant or relax at a cozy table in a sit-down restaurant?

Note

One small problem with my restaurantanalogy for Ajax is that it implies that AjaxWeb applications are somehow slower thantraditional Web applications This is not thecase Ajax applications are no faster orslower in terms of raw data processing Infact, they often give the impression ofbeing faster because processing is typically

Trang 36

going on in the background when you don'teven realize it.

Trang 37

Chapter 1 Ajax and a Brave New World WideWeb

Chapter 2 Inside an Ajax Application

Trang 38

Chapter 1 Ajax and a Brave New World Wide Web

Ajax in Cartoons

Ajax Corporation is a fictional corporationused by Metro-Goldwyn-Mayer (MGM) as aparody of Warner Brothers' Acme

Corporation, which is featured prominently

in Road Runner cartoons The Ajax Corporation is primarily referenced in Tom

and Jerry cartoons.

So I'm waiting for my order at a fast food restaurant the otherday, and I started to question why the word "fast" had any

business in the description of this particular place I was eager

to have a seat and flip through a magazine, not loiter in a

crowded lobby waiting for my "fast" food This situation got methinking about Ajax and how it improves the overall Web

experience Yes, in an arguably twisted way, it's possible to look

at Ajax through the greasy lens of a hamburger wrapper And injust a moment you'll see how

Although it isn't strictly considered an acronym, the name Ajaxultimately derives from Asynchronous JavaScript and XML Thekey benefits to Ajax are that it allows you to receive small

chunks of data over a Web connection asynchronously, meaningyou don't have to wait around for it, and in most cases you canavoid a full Web page reload The real trick to using Ajax

effectively is to get your brain wrapped around what it can do,which is far more important than what it is or why people seem

so enamored by it Ajax is one of those truly rare Web

innovations whose benefits are immediately understood onceyou see it used in the proper context And sort of like the

popular 3M commercials you sometimes see on television, you

Trang 39

This chapter starts you off with a healthy dose of Ajax realism,with a clear focus on what types of problems it aims to solveand why that matters to you Yes, I also get around to

explaining what it is and why people are enamored by it, butthat's just icing on the cake

Dining with Ajax

Getting back to the fast food analogy in the opener, the

scenario is a crowded fast food restaurant where you have tostand around waiting for your food before you can sit down andget comfortable Contrast this fast food dining experience with afull-service restaurant where your meal is delivered to your

table after you've already sat down and ordered There is a

considerable luxury in being seated at a table going about yourbusiness while someone is busy working away in the kitchenpreparing the meal In the fast food alternative, you must standaround waiting for your food before you can take a seat and getcomfortable, assuming you consider fast food seating

comforting The point I'm getting at is that with the fast foodapproach, the time it takes to prepare your food is time out ofyour pocket because your dining experience is on hold until thefood is ready With a sit-down dinner, you're able to enjoy adrink, munch on an appetizer, and read a magazine, or talk it

up with your dining companion while you wait These are verydifferent experiences, as illustrated in Figure 1.1

Figure 1.1 The time it takes to prepare food goes relatively unnoticed in a full-service dinner because you

are free to enjoy the dining experience.

Trang 40

technique that offers to upgrade your Web pages to a sit-downdining experience Traditional Web applications force you to waitwhile data is searched or otherwise processed on the server.Not so with Ajax An Ajax Web application goes off and

performs its data processing in the background, leaving you tocontinue to interact with the Web page in the meantime Thismay seem like a subtle distinction, but it is not Just ask

yourself, would you rather stand in line at a not-so-fast-foodrestaurant or relax at a cozy table in a sit-down restaurant?

Note

One small problem with my restaurantanalogy for Ajax is that it implies that AjaxWeb applications are somehow slower thantraditional Web applications This is not thecase Ajax applications are no faster orslower in terms of raw data processing Infact, they often give the impression ofbeing faster because processing is typically

Ngày đăng: 19/04/2019, 13:40

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm