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.