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
54
Chapter 1
Right now, your updatePage() function assumes that the server is nished
when it runs... but that’s not the case! To understand what’s going on with your
request, it’s time to learn about ready states. Your request object has a ready
state that tells the browser quite a bit about what state the request is in.
Make sure the server is finished
function getBoardsSold() {
createRequest();
var url = “getUpdatedBoardSales-ajax.php”;
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
This property sets
the function that the
browser should run every
time that the request’s
ready state changes.
updatePage()createRequest() getBoardsSold()
A ready
state
tells the
browser
what stage
a request
is in.
Do you remember the property you used in getBoardsSold() to tell
the browser what to do when the server sent back a response? Take a look
to refresh your memory:
Ready states are connected to your request
object’s onreadystatechange property
This property affects every ready state,
not just the one indicating that the
server is nished with a request.
Web Browser
Internet Explorer
Firefox
Opera
Safari
Mozilla
PHP script
Request
Response
1
2
3
4
Here, the connection is just
getting initialized.
Now the request is
being worked on...
The server’s almost nished
with the request now.
All done! The
server’s response is
ready to be used.
These are the request’s ready sta ...
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