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
46
Chapter 1
Remember, we’ve got to tell the browser what to do with the server’s
response to our request before we make the request... because once
the request is made, getBoardsSold() nishes running, and our
JavaScript code won’t know what’s going on with the request. Fortunately,
the request object we’ve been using has a property just for this purpose:
If you put the name of a
function here, the browser will
run that function when it gets
a response from the server.
function getBoardsSold() {
createRequest();
var url = “getUpdatedBoardSales-ajax.php”;
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
Sending instructions to the browser
Be sure you set this
property before you call
send(), or this function
won’t get run.
updatePage()createRequest() getBoardsSold()
Time to go back to
getBoardsSold(), now that
we’ve learned a little more
about web browsers.
So how do we talk to the browser? So far,
all the code we’ve written just deals with
that JavaScript request object. Wait a
second... that’s it! Can we use the request
object to talk to the browser?
who has the server’s response?
JavaScript requires that you
leave off the parentheses on
the function name here.
you’re on your way 4
47
Q:
The server talks to the browser, the browser
talks to the Ja ...
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