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 ...