86
Chapter 2
Creating a request object
This step is all about making a request to the Break Neck server.
For that, we need a request object that our JavaScript function can
use. Luckily, though, you already wrote code that creates a request
object back in Chapter 1, in the createRequest() function.
You should remember createRequest() from Chapter 1.
Let’s take a look at that JavaScript again, and make sure it’s ready
to use in the Break Neck app:
Man, Break Neck pizza rocks. There’s
nothing like a breakfast of cold pizza, a
whipped latte from Starbuzz, and the
Webville Times to read.
<script>
var request...
function foo()
{
...
}
</script>
JavaScript
<script>
var request...
function foo()
{
...
}
</script>
Customer’s Phone Number
Customer’s Address
Customer’s Order
<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) {
try {
request = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (failed) {
request = null;
}
}
}
if (request == null)
alert(“Error creating request object!”);
}
function getCustomerInfo() {
var phone = document.getElementById(“phone”).value;
createRequest( ...