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
142
Chapter 3
function getCustomerInfo() {
var phone = document.getElementById(“phone”).value;
var url = “lookupCustomer.php?phone=” + escape(phone);
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
var customerAddress = request.responseText;
document.getElementById(“address”).value = customerAddress;
}
}
}
Here’s where we send the request
to the Break server.
Customer’s
Phone Number
Break Neck Pizza is an asynchronous app
Take another look at the Break Neck Pizza Ajax application. You type in your phone number,
and then move to the pizza order or address. The page’s JavaScript then gets your phone
number from the form, and sends the request for your address to the web server. If your
address takes a long time to look up, you’ll notice that you can go ahead and enter your pizza
order without having to wait for the server to return your address.
And here’s the callback function
that’s run when the response
comes back from the server.
Since this is an asynchronous request, from
the time the browser sends the request
to get your address to the time it gets a
response, you can still go on using the web
page. You won’t be stuck.
Remember, this parameter is how
you tell the request object to send
your request asynchronously.
Customer’s
Address and Order
Here’s the ...
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