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
16
Chapter 1
Let’s get back to updating Katie’s web report. First up, you need a function that creates
a new object to make requests to the server. This turns out to be a bit tricky, because
different browsers have different ways of creating this object. To help you out, we’ve
written some “pre-assembled” JavaScript for you. Whenever you see the logo,
it means you’ll have to take some code on faith, like this code below that creates an object
to make requests to the server. Trust us though—you’ll learn all about this code in more
detail in the chapters to come. For now, just type it in and see what it can do.
Pre-Assembled
JavaScript
n
n
Pre-Assembled
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!”);
}
Pre-Assembled
JavaScript
n
Step 1: Creating a request object
This line tries to create a new
request object.
These two lines try and create the
request object, too, but in a way that
works on Internet Explorer.
This is the type of the
request object.
...and we can spit out an error
message to users with JavaScript’s
alert() function.
Here’s a variable to hold the request object.
If something ...
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