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
160
Chapter 3
function sendRequest(url) {
request.onreadystatechange = serveDrink;
request.open(“GET”, url, true);
request.send(null);
}
function orderCoffee() {
var name = document.getElementById(“name”).value;
var beverage = getBeverage();
var size = getSize();
var url = “coffeemaker.php?name=” + escape(name) +
“&size=” + escape(size) +
“&beverage=” + escape(beverage) +
“&coffeemaker=1”;
sendRequest(url);
}
We’ll write the functions to get the size and
beverage requested in just a few pages.
sendRequest() sets up the callback
function for the server response
(serveDrink) and sends a GET
request to the URL passed in from
makeFreshCoffee().
sending a request to brew coffee
Writing JavaScript to send the request
Now let’s write the JavaScript to send the request
to the coffee-making script:
JavaScript
PHP script
HTML form
All this code should go in
your copy of coffee.js.
orderCoffee() builds the request URL,
using the coffeemaker.php script and all
the information it got from the coffee
order form.. It requests the rst coffee
maker be used to brew the coffee.
coffee.js
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