you’re on your way �
377
xml versus json
You don’t need a special object
model to work with JSON data
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
// Get the updated totals from the JSON response
var jsonData = eval(‘(‘ + request.responseText + ‘)’);
var totalBoards =
jsonData.totals[0].boardsSold;
var totalBoots =
jsonData.totals[0].bootsSold;
var totalBindings =
jsonData.totals[0].bindingsSold;
// Update the page with new totals
totals[0]
returns the
rst (and only)
“totals” item.
jsonData is
the JSON
data object.
Once you have the right “totals” item,
you can just use the name of the
piece of data you want... boardsSold,
bootsSold, or bindingsSold.
Here’s some JavaScript that
works with this JSON data.
Web Browser
getNew Totals()
<script>
var request...
function foo()
{
...
}
</script>
Internet Explorer
Firefox
Opera
Safari
Mozilla
JavaScript
We’ll look at
how to get the
JSON data from
the server’s
response in just
a few pages.