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