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
you’re on your way 4
37
next generation applications
You’ve uncovered the trickiest part of
asynchronous web programming: if
asynchronous code doesn’t wait around for
a response from the server, how do we use
that response? And where does the server’s
response go in the rst place?
You already know about web pages,
which can use event handlers to call
JavaScript functions. And you’ve seen
how asynchronous JavaScript can make
requests to a web server. To complete the
asynchronous picture, though, there’s
another important piece of the puzzle...
Where does the response go?
So if getBoardsSold() nishes running
before the server responds, where does
the response go? And how can we make sure
that updatePage() runs when the server’s
nished with our request?
Remember, getBoardsSold() makes
an asynchronous request. That means that
the JavaScript doesn’t wait around for an
answer from the server.
In fact, the getBoardsSold() function
will probably nish running before the
getUpdatedBoardSales-ajax.
php script even has a chance to nish
processing your request.
Ajax is asynchronous JavaScript
I think we should call the updatePage()
function at the end of getBoardsSold().
Then updatePage() can get the response
from the server, right?
function getBoardsSold() {
createRequest();
var url =
“getUpdatedBoardSales-ajax.php”;
request.open(“GET”, url, true);
request.send(null);
updatePage();
}
This won’t ...
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