Re: ny times best seller api

From: Nate Hill <nathanielhill_at_nyob>
Date: Thu, 29 Sep 2011 18:21:39 -0700
To: CODE4LIB_at_LISTSERV.ND.EDU
Thanks Tom.  I guess I just don't understand jQuery $.each(), I thought with
that I didn't need a javascript for loop- that each() would just plow
through and return everything.
Cheers, I appreciate the help.
N

On Thu, Sep 29, 2011 at 6:14 PM, Tom Keays <tomkeays_at_gmail.com> wrote:

> 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()
> >
>



-- 
Nate Hill
nathanielhill_at_gmail.com
http://www.natehill.net
Received on Thu Sep 29 2011 - 21:22:04 EDT