Skip to Main Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate content levelBeginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
you’re on your way 4
189
asynchronous applications
Creating two request objects
First, we need to actually create both request objects. Open up
ajax.js and make the following changes, so that we’re creating
two request objects instead of just one:
var request = null;
function createRequest() {
var request = null;
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!”);
} else {
return request;
}
}
var request1 = createRequest();
var request2 = createRequest();
ajax.js
We no longer want to create a single
request object. Delete this line.
Now, turn this code back into a
function, so we can run it more
than once easily.
If the request object is created
successfully, return it as the result
of the function.
Finally, in static JavaScript, create two
request objects. Assign each the return
value of the createRequest() function.
This is your ajax.js le.
When this nishes running, you’ll have
two request objects-request1 and
request2-created and ready to use.
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

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
Head First Ajax

Head First Ajax

Rebecca M. Riordan

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content