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
146
Chapter 3
<html>
<head>
<title>Break Neck Pizza Delivery</title>
<link rel=”stylesheet” type=”text/css” href=”breakneck.css” />
<script language=”javascript” type=”text/javascript”>
var request = null;
function createRequest() {
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (othermicrosoft) {
Three ingredients for asynchronous coffee
There are three basic parts to the Ajax-powered coffee maker:
PHP script
You’ll also need a server-side coffee-making script, which
will brew coffee anytime it gets a request.
3
Server-side coffee-making script
This is the PHP script that
makes coffee. You’ll send all
the coffee orders to this
script for brewing.
This script can handle the
brewing for both coffee
makers, since two cups can
be brewing at the same
time in the app.
Second, you’ll need some JavaScript, including:
2
JavaScript code
JavaScript
orderCoffee()
serveDrink()
w Code to create a request object.
w A function to send an order to the
coffee-making script.
w A function to serve a drink when it’s
been brewed.
w Event handlers to connect the web form
buttons to these JavaScript functions.
First, you’ll need the HTML for
the coffee maker web page.
The page needs to take orders,
and report on the status of the
two coffee makers.
1
Coffee maker HTML
</p>
<h3>Beverage</h3>
<p>
<input type=”radio” name=”beverage”
value=”mocha ...
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