Section 2.11. On to the JavaScript


2.11. On to the JavaScript

Now you're ready to dig into some JavaScript. You know the name of the function that you'll be using to get the customer's phone number: getCustomerInfo(). This function needs to send the customer's phone number to Break Neck's server, and ask for that customer's address.

Let's start out with just the function name:

     function getCustomerInfo()     ...Here's where all your code will go.     }The first thing we need to do is get the customer's phone number from the HTML form. 

BRAIN POWER

Do you think there could be any problems with event handlers that run JavaScript code that then makes asynchronous requests? What would happen if the pizza form sent a request for an address, and then sent another request before the first response was returned? What do you think the customer would see happen on the order form?


Just Do It

Open up the examples for Head Rush Ajax that you downloaded from http://www.headfirstlabs.com. Go into the chapter02/breakneck/ folder, and you'll find pizza.html. This is the Break Neck order form, but you need to make some changes to bring it up to speed.

First, make sure the HTML matches the answers from the Code Magnets exercise, on page 80. Next, you need to add <script> tags to the <head> section of the HTML, just like you did for the Boards app back in Chapter 1. Finally, go ahead and enter in the empty getCustomerInfo() function. We'll be filling this function in over the next several pages.

Be sure not to go on to the next page until you've got your version of pizza.html updated.





Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net