Section 2.15. getCustomerInfo() at a glance


2.15. getCustomerInfo() at a glance

You should be pretty comfortable with making a GET request after fixing up Katie's Boards 'R' Us app back in Chapter 1. Here's similar code for getCustomerInfo(); most of this JavaScript should look similar to the code you wrote Chapter 1:

     function getCustomerInfo() {You've already set up the Break Neck form to call this function whenever the phone number field is changed.       var phone = document.getElementById("phone").value;This is the code to get the phone number, using the DOM, that you wrote in Step 1.       createRequest()  ;You wrote this function in Chapter 1; it creates a new request object.       var url = "lookupCustomer.php?phone=" +Here's the URL for the script on the server...                  escape(phone);...and this sends the phone number as a request parameter.       request.open("GET", url, true);This sets up the request object to make a GET request.       request.onreadystatechange = updatePage;This tells the browser what function to run when the request's ready state changes.       request.send(null)  ;This last line sends the request, with no additional data other than what is in the request URL.     } 

Say What?

It's OK if you've still got some questions about this code. We're going to look at each line in detail throughout the chapter, so don't feel like you have to understand it all now.





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