A Brain-Friendly Guide Head First Ajax Fireside Chats Learn how Sally did two things at the same Learn how to make time with asynchronous your web pages programming talk and listen at the same time Toknl Boarde Seld Transfer your data with plain text, XML,and JSON Make your clunky web apps feel like Get a handle dynamic,responsive on trees and desktop applications the Document Object Model O'REILLY Rebecca M.Riordan
Chapter 1.using ajax Table of Contents Chapter 1.using ajax....................................... Section 1.1.Web pages:the old-fashioned approach...... Section 1.2.Web pages reinvented........... …3 Section 1.3.So what makes a page "Ajax"?. .5 Section 1.4.Rob's Rock'n'Roll Memorabilia. 6 Section 1.5.Ajax and rock'n'roll in 5 steps. .12 Section 1.6.Step 1:Modify the XHTML.... ,14 Section 1.7.Step 2:Initialize the JavaScript.... .16 Section 1.8.Step 3:Create a request object.... .20 Section 1.9.Step 4:Get the item's details...... 22 Section 1.10.Let's write the code for requesting an item's details..... 24 Section 1.11.Always make sure you have a request object before working with it. 25 Section 1.12.The request object is just an object..... .26 Section 1.13.Hey,server...will you call me back at displayDetailsO,please?. 27 Section 1.14.Use send(to send your request......... 28 Section 1.15.The server usually returns data to Ajax requests............................... 30 Section 1.16.Ajax is server-agnostic..... 4440440444444444444444044044444044444444404444444 Section 117.Use a callback function to work with data the server returns.. 35 Section 1.18.Get the server's response from the request object's responseText property..................................................36 Section 119.Goodbye traditional web apps.....38 Secti0nl.20。AjXACT0StiC439 Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tra nsmitted in any form by any means without the prior written permission for reprints and excerpts from the publis er.Redistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC107)or that otherwise violates the Safari Terms of Service is strictly prohibited
Table of Contents Chapter 1. using ajax.................................................................................... 1 Section 1.1. Web pages: the old-fashioned approach..................................................................................................................... 2 Section 1.2. Web pages reinvented................................................................................................................................................. 3 Section 1.3. So what makes a page "Ajax"?..................................................................................................................................... 5 Section 1.4. Rob's Rock 'n' Roll Memorabilia................................................................................................................................. 6 Section 1.5. Ajax and rock 'n' roll in 5 steps.................................................................................................................................. 12 Section 1.6. Step 1: Modify the XHTML........................................................................................................................................ 14 Section 1.7. Step 2: Initialize the JavaScript................................................................................................................................. 16 Section 1.8. Step 3: Create a request object.................................................................................................................................. 20 Section 1.9. Step 4: Get the item's details..................................................................................................................................... 22 Section 1.10. Let's write the code for requesting an item's details............................................................................................... 24 Section 1.11. Always make sure you have a request object before working with it...................................................................... 25 Section 1.12. The request object is just an object......................................................................................................................... 26 Section 1.13. Hey, server... will you call me back at displayDetails(), please?............................................................................. 27 Section 1.14. Use send() to send your request.............................................................................................................................. 28 Section 1.15. The server usually returns data to Ajax requests.................................................................................................... 30 Section 1.16. Ajax is server-agnostic.............................................................................................................................................. 31 Section 1.17. Use a callback function to work with data the server returns................................................................................. 35 Section 1.18. Get the server's response from the request object's responseText property.......................................................... 36 Section 1.19. Goodbye traditional web apps................................................................................................................................. 38 Section 1.20. AjaxAcrostic............................................................................................................................................................. 39 Chapter 1. using ajax Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1.using ajax Page Return to Table of Contents 1 using ajax 米 米 Web Apps for a New 米 Generation I'll just take a little nap while I'm waiting for my web app to respond... Tired of waiting around for your page to reload? Frustrated by clunky web application interfaces?It's time to give your web apps that slick,responsive desktop feel.And how do you do that?With Ajax,your ticket to building Intemet applications that are more interactive,more responsive,and easier to use.So skip your nap;it's time to put some polish on your web apps.It's time to get rid of unnecessary and slow full-page refreshes forever. this is a new chapter Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or transmitted in written permission for reprints and excerpts from the publis hathedeu otherwise violates the Safari Terms of Service is strictly prohibited
this is a new chapter 1 using ajax Web Apps for a New Generation Tired of waiting around for your page to reload? )UXVWUDWHGE\FOXQN\ZHEDSSOLFDWLRQLQWHUIDFHV",W¶VWLPHWRJLYH\RXUZHEDSSVWKDW VOLFNUHVSRQVLYHGHVNWRSIHHO$QGKRZGR\RXGRWKDW":LWKAjax\RXUWLFNHWWR EXLOGLQJ,QWHUQHWDSSOLFDWLRQVWKDWDUHmore interactive, more responsive, DQGeasier to use6RVNLS\RXUQDSLW¶VWLPHWRSXWVRPHSROLVKRQ\RXUZHEDSSV,W¶VWLPHWR JHWULGRIXQQHFHVVDU\DQGVORZIXOOSDJHUHIUHVKHVIRUHYHU ,·OOMXVWWDNHDOLWWOHQDS ZKLOH,·PZDLWLQJIRUP\ ZHEDSSWRUHVSRQG Chapter 1. using ajax Page 1 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
Chapter 1.using ajax Page2 Return to Table of Contents old-fashioned web apps Web pages:the old-fashioned approach With traditional web pages and applications,every time a user clicks on something,the browser sends a request to the server,and the server responds with a whole new page.Even if your user's web browser is smart about caching things like images and cascading style sheets,that's a lot of traffic going back and forth between their browser and your server...and a lot of time that the user sits around waiting for full page refreshes. The user clicks somcthing码on your page 个 The browser sends a request to the server The server sends back a whole new page, with all the changed The user clicks information. something else. The browser sends another request to the server. Most of the time,only a single line or image is changing but there's still a complete page refresh. And the server H sends back another whole page... 2 Chapter 1 Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or any form by any means without the prior written permission for reprints and excerpts from the publis er.Re edistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC1o7)or that otherwise violates the Safari Terms of Service is strictly prohibited
2 Chapter 1 Web pages: the old-fashioned approach With traditional web pages and applications, every time a user clicks on something, the browser sends a request to the server, and the server responds with a whole new page. Even if your user’s web browser is smart about caching things like images and cascading style sheets, that’s a lot of traffic going back and forth between their browser and your server... and a lot of time that the user sits around waiting for full page refreshes. The user clicks something on your page. The browser sends a request to the server. The server sends back a whole new page, with all the changed information. The user clicks something else. The browser sends another request to the server. And the server sends back another whole page... Most of the time, only a single line or image is changing... but there’s still a complete page refresh. old-fashioned web apps Chapter 1. using ajax Page 2 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1.using ajax Page3 Return to Table of Contents using ajax Web pages reinvented Using Ajax,your pages and applications only ask the server for what they really need-just the parts of a page that need to change,and just the parts that the server has to provide.That means less traffic,smaller updates,and less time sitting around waiting for page refreshes. With Ajax,the browser only sends and receives the parts of a page that need to change. This time,your page's code creates a special request object that the browser sends to the server The server updates the request objcet.. With Ajax,the user doesn't have to suffer page flickers or lots of waiting around. they can even keep using the page while the request is .and your code tells the being processed. browser to update only the parts of the page that have changed. Sometimes the browser doesn't have to talk to the server at all. The seript can update the The browser calls image without the server-side The user elieks a function in Program at all! something your script file. The script tells the browser how to update the page...all without a page refresh. you are here Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tra mitted in any form by any means without the prior written permission for reprints and excerpts from the publis er.Redistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC107)or that otherwise violates the Safari Terms of Service is strictly prohibited
you are here 3 using ajax Web pages reinvented This time, your page’s code creates a special request object that the browser sends to the server. The server updates the request object... ...and your code tells the browser to update only the parts of the page that have changed. Using Ajax, your pages and applications only ask the server for what they really need—just the parts of a page that need to change, and just the parts that the server has to provide. That means less traffic, smaller updates, and less time sitting around waiting for page refreshes. With Ajax, the browser only sends and receives the parts of a page that need to change. The user clicks something. Sometimes the browser doesn’t have to talk to the server at all. The browser calls a function in your script file. The script tells the browser how to update the page... all without a page refresh. The script can update the image without the server-side program at all! request request With Ajax, the user doesn’t have to suffer page flickers or lots of waiting around... they can even keep using the page while the request is being processed. function getDetails { ... function getDetails { ... Chapter 1. using ajax Page 3 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1.using ajax Page4 Return to Table of Contents ajax is a methodology Okay.I get that Ajax makes web pages respond faster,but what exactly is it? Ajax is a new way of using existing technologies. Ajax isn't a whole new technology that you have to learn,like CSS or JavaScript,or a set of graphics techniques you'll need to crack open PhotoShop to accomplish.Ajax is just a new way of thinking about how to do what you're already doing,using technologies you probably already know. The browser sends requests and gets responses from a web server. Your page can use im39e,月ash animations,Silverlight, or anything else you want or need. function getDetails #mystyle( XHTML files scripts style sheets other resources Most web programmers and designers are already using some,or even all,of these technologies. 4 Chapter 1 Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tr nsmitted in any form by any means without the pro written permission for reprints and excerpts from the publis er.Re edistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC1o7)or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1 2ND\,JHWWKDW$MD[PDNHVZHESDJHV UHVSRQGIDVWHUEXWZKDWH[DFWO\LVLW" Ajax is a new way of using existing technologies. Ajax isn’t a whole new technology that you have to learn, like CSS or JavaScript, or a set of graphics techniques you’ll need to crack open PhotoShop to accomplish. Ajax is just a new way of thinking about how to do what you’re already doing, using technologies you probably already know. ... function getDetails { ... #mystyle{ ... XHTML files scripts style sheets other resources The browser sends requests and gets responses from a web server. Your page can use images, Flash animations, Silverlight, or anything else you want or need. Most web programmers and designers are already using some, or even all, of these technologies. ajax is a methodology Chapter 1. using ajax Page 4 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
Chapter 1.using ajax Page5 Return to Table of Contents using ajax So what makes a page "Ajax"? Ajax is a way of designing and building web pages that are as interactive and responsive as desktop applications.So what does that mean for you?You handle things at the client's browser whenever you can.Your pages make asynchronous requests that allow the user to keep working instead An asynchronous of waiting for a response.You only update the things on your pages that actually change.And best of all,an Ajax page is built using standard Internet request is a technologies,things you probably already know how to use,like: request that ● XHTML occurs behind ● Cascading Style Sheets ● the scenes. JavaScript Ajax applications also use a few things that have been around for a while but Your users can may be new to you,like: keep working ● The XmlHttpRequest We'll look at all of XML JSON these in detail before while the we're through. ● The DOM request is taking place. there are no Dumb Questions Doesn'Ajax stand for Asynchronous JavaScript and XML”? But aren't all wb pages asynchronous?Lik when a browser loads an image while I'm already looking at the Sont ol oe re page? don't use JavaScript or XML,it's more useful to define Ajax as a Browsers are asynchronous,but the standard web page way of building web pages that are as responsive and interactive isn't Usually when a web page needs information from a as desktop applications,and not worry too much about the exact server-side program,everything comes to a complete stop until technologies involved. the server responds...unless the page makes an asynchronous request And that'what Ajax is all about. What exactly doesasynchronous"mean? In ax.you can make thserve Butall Ajaxpageuse thatequstc right? making your user wait around for a response.That's called an asynchronous request,and it's the core of what Ajax is all Nope.Lots do,and we spend a couple of chapters about. mastering XMLHttpRequest,but it's not a requirement.In fact,lots of apps that are considered Ajax are more about user interactivity and design than any particular coding technique. you are here 5 Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tra smitted in any form by any means without the pro written permission for reprints and excerpts from the publis er.Redistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC107)or that otherwise violates the Safari Terms of Service is strictly prohibited
you are here 5 using ajax So what makes a page “Ajax” ? Ajax is a way of designing and building web pages that are as interactive and responsive as desktop applications. So what does that mean for you? You handle things at the client’s browser whenever you can. Your pages make asynchronous requests that allow the user to keep working instead of waiting for a response. You only update the things on your pages that actually change. And best of all, an Ajax page is built using standard Internet technologies, things you probably already know how to use, like: Q : Doesn’t Ajax stand for “Asynchronous JavaScript and XML”? A : Sort of. Since lots of pages that are considered “Ajax” don’t use JavaScript or XML, it’s more useful to define Ajax as a way of building web pages that are as responsive and interactive as desktop applications, and not worry too much about the exact technologies involved. Q : What exactly does “asynchronous” mean? A : In Ajax, you can make requests to the server without making your user wait around for a response. That’s called an asynchronous request, and it’s the core of what Ajax is all about. Q : But aren’t all web pages asynchronous? Like when a browser loads an image while I’m already looking at the page? A : Browsers are asynchronous, but the standard web page isn’t. Usually when a web page needs information from a server-side program, everything comes to a complete stop until the server responds... unless the page makes an asynchronous request. And that’ what Ajax is all about. Q : But all Ajax pages use that XMLHttpRequest object, right? A : Nope. Lots do, and we’ll spend a couple of chapters mastering XMLHttpRequest, but it’s not a requirement. In fact, lots of apps that are considered Ajax are more about user interactivity and design than any particular coding technique. Ajax applications also use a few things that have been around for a while but may be new to you, like: We’ll look at all of these in detail before we’re through. XHTML Cascading Style Sheets JavaScript The XmlHttpRequest XML & JSON The DOM An asynchronous request is a request that occurs behind the scenes. Your users can keep working while the request is taking place. Chapter 1. using ajax Page 5 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1.using ajax Page6 Return to Table of Contents rob needs your help Rob's Rock n'Roll Memorabilia Meet Rob.He's put all his savings into an online rock n'roll memorabilia store.The site looks great,but he's still been getting tons of complaints.Customers are clicking on the thumbnail images on the inventory page,but the customers'browsers are taking forever before they show information about the selected item.Some of Rob's users are hanging around,but most have just stopped coming to Rob's online shop altogether. ROUS ROCK”ROL VEMORI When the user clicks an item,a bigger This panc picture of the image contains is displayed here... thumbnails of the items Rob has for sale. .and the details about the item are shown here. I'm desperate...but I can't afford a more powerful server or a team of web experts 0 Ajax pages only talk to the server when they have to... and only about what the server knows. The problem with Rob's site isn't that his server is too slow,but that his pages are sending requests to the server all the time...even when they don't need to. 6 Chapter 1 Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tra nsmitted in any form by any means without the prior written permission for reprints and excerpts from the publis er.Redistribution or other use that violates the fair use priviledge under U.S.copyright laws (see 17 USC1o7)or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1 Rob’s Rock ‘n’ Roll Memorabilia Meet Rob. He’s put all his savings into an online rock n’ roll memorabilia store. The site looks great, but he’s still been getting tons of complaints. Customers are clicking on the thumbnail images on the inventory page, but the customers’ browsers are taking forever before they show information about the selected item. Some of Rob’s users are hanging around, but most have just stopped coming to Rob’s online shop altogether. This pane contains thumbnails of the items Rob has for sale. When the user clicks an item, a bigger picture of the image is displayed here... ...and the details about the item are shown here. ,·PGHVSHUDWHEXW,FDQ·W DIIRUGDPRUHSRZHUIXOVHUYHURU DWHDPRIZHEH[SHUWV Ajax pages only talk to the server when they have to... and only about what the server knows. The problem with Rob’s site isn’t that his server is too slow, but that his pages are sending requests to the server all the time... even when they don’t need to. rob needs your help Chapter 1. using ajax Page 6 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
Chapter 1.using ajax Page7 Return to Table of Contents using ajax Sharpen your pencil Here's what Rob's online store does right now.What's wrong with this picture? The browser sends The user clieks the selected item's ID to the server. The server sends back a new page, with the seleeted item's information The user elicks another thumbnail. The browser sends the new item's ID to the server. The server sends back another whole The user gets new page. 七ired of waiting and does something else... How would Ajax change this diagram?Write down what you think should happen on Rob's site. you are here > Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tra itted in any form by any means without the pro written permission for reprints and excerpts from the publis er.Re edistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC1o7)or that otherwise violates the Safari Terms of Service is strictly prohibited
you are here 7 using ajax The user clicks a thumbnail. The browser sends the selected item’s ID to the server. The server sends back a new page, with the selected item’s information. The browser sends the new item’s ID to the server. The server sends back another whole The user gets new page. tired of waiting and does something else... The user clicks another thumbnail. Here’s what Rob’s online store does right now. What’s wrong with this picture? How would Ajax change this diagram? Write down what you think should happen on Rob’s site. Chapter 1. using ajax Page 7 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1.using ajax Page8 Return to Table of Contents asynchronous apps do more than one thing at once Sharpen your pencil oution Your job was to think about how Ajax could help save Rob's site...and his business.With Ajax,we can completely remove all the page refreshes on his inventory page.Here's what that would look like: Clicking an image calls a JavaScript function. The function creates The user clicks a request object that a thumbnail. asks the server for a deseription of the item. 个 The funetion also The browser changes the image sends the to match the request object selected item. to the server behind the scenes The browser requests the new image from the server...but that's not something your page worries about. Only the part of the page that actually changed is updated...but The server returns the user still sces the new image and a new image and a response to the the selected item's request to the description. user's browser. BULLET POINTS ■ Asynchronous requests allow more than one thing to happen at the same time. Only the part of a web page that needs to change gets updated. The page isn't frozen while the server is returning data to the browser. 8 Chapter 1 Chapter 1.using ajax Head First Ajax By Rebecca M.Riordan ISBN:9780596515782 Publisher:O'Reilly Prepared for Ann Cherkis,Safari ID:maottw@gmail.com Print Publication Date:2008/08/26 User number:1673621 Copyright 2008.Safari Books Online.LLC. This PDF is exclusively for your us in accordance with the Safari Terms of Service.No part of it may be reproduced or tra itted in any form by any means without the prior written permission for reprints and excerpts from the publis er.R edistribution or other use that violates the fair use priviledge under U.S.copyright laws(see 17 USC1o7)or that otherwise violates the Safari Terms of Service is strictly prohibited
Chapter 1 The user clicks a thumbnail. Clicking an image calls a JavaScript function. The function also changes the image to match the selected item. The function creates a request object that asks the server for a description of the item. The browser sends the request object to the server, asynchronously, behind the scenes. The browser requests the new image from the server... but that’s not something your page worries about. Only the part of the page that actually changed is updated... but the user still sees a new image and the selected item’s description. Asynchronous requests allow more than one thing to happen at the same time. Only the part of a web page that needs to change gets updated. The page isn’t frozen while the server is returning data to the browser. request request Your job was to think about how Ajax could help save Rob’s site... and his business. With Ajax, we can completely remove all the page refreshes on his inventory page. Here’s what that would look like: The server returns the new image and a response to the request to the user’s browser. function getDetails { ... asynchronous apps do more than one thing at once Chapter 1. using ajax Page 8 Return to Table of Contents Chapter 1. using ajax Head First Ajax By Rebecca M. Riordan ISBN: 9780596515782 Publisher: O'Reilly Prepared for Ann Cherkis, Safari ID: maottw@gmail.com Print Publication Date: 2008/08/26 User number: 1673621 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited