you’re on your way 4
85
ajax requests
getCustomerInfo() at a glance
function getCustomerInfo() {
var phone = document.getElementById(“phone”).value;
createRequest();
var url = “lookupCustomer.php?phone=” +
escape(phone);
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
You’ve already set up the Break Neck
form to call this function whenever the
phone number eld is changed.
Here’s the URL for the
script on the server...
...and this sends the
phone number as a
request parameter.
This sets up
the request
object to make
a GET request.
This tells the browser what
function to run when the
request’s ready state changes.
This last line sends the
request, with no additional
data other than what is
in the request URL.
This is the code to get the
phone number, using the DOM,
that you wrote in Step 1.
You wrote this
function in
Chapter 1; it
creates a new
request object.
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.
You should be pretty comfortable with making a GET request after
xing 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: