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 ...