Re: ny times best seller api

From: Tom Keays <tomkeays_at_nyob>
Date: Thu, 29 Sep 2011 21:14:52 -0400
To: CODE4LIB_at_LISTSERV.ND.EDU
I haven't quite figured out why the each is not behaving as expected, but
this worked, returning all 20 titles delivered by the JSON.

I expected the each() to parse down from the single results container, so
why book_details has to be referenced by incrementing the results array (or
is it an object?) seems wrong.

<!DOCTYPE html>
<html>
<head>
<meta charset="iso-8859-1">
<title> NY Times Hardcover Fiction Bestsellers </title>
<script type="text/javascript" src="
http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        //json request to new york times via proxy
        $.getJSON('http://www.sjpl.org/otherscripts/callback.php?callback=?
',
        function(data){
            for(var i = 0; i < 20; i++){
                $.each(data.results[i].book_details, function(n,item){
                    var bookTitle = item.title;
                    $('#container').append('<p>'+bookTitle+'</p>');
                });
            };
        });
    });
</script>

</head>
<body>

<div id="container"></div>

</body>
</html>



On Thu, Sep 29, 2011 at 5:33 PM, Nate Hill <nathanielhill_at_gmail.com> wrote:

> *Here's my problem:*
> I can only return the book title and the isbn by specifying which one in
> the
> array I want, so I'm using: data.results[0].book_details to pull the first
> title.
> Something is wrong with the way I'm using $.each()
>
Received on Thu Sep 29 2011 - 21:15:19 EDT