Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
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:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content