18
Chapter 1
<script>
var request...
function
getBoardsSold()
{
...
}
</script>
Request Total
Boards Sold
Now that you can get a request object with createRequest(), you’re ready for the
next step: writing the getBoardsSold() JavaScript function. This function will use the
new object to request the total number of boards sold from the server. Let’s gure out what
this function needs to do, and then we can get back to coding Katie’s app. Remember our
diagram? Here’s the step we’re working on:
Here’s what you’ll need to do to make getBoardsSold() work:
Step 2: Requesting updated sales
Set up the request object to make a
connection.
Request an updated number of
boards sold.
Figure out what URL you need to
connect to so you can get updated
board sales.
Create a new request object by calling
the createRequest() function.
You can use the pre-assembled
JavaScript from the last two
pages to take care of this.
You can use this number
later, in Step 3, when you
update the page with new
values. You’ll tackle this in
just a little while.
Here’s where you’ll use
that request object you
created in createRequest().
Katie already has this URL in her
form, so this should be simple enough.
Open up your boards.html le, and add a new JavaScript function called getBoardsSold(),
right after createRequest(). Then, see if you can add a line of JavaScript in
getBoardsSold() to create a new request object (that’s Step ...