Print

Print


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 <[log in to unmask]> 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>
> <!cript type="text/javascript" src="
> http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
> <!cript 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 <[log in to unmask]>
> 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
[log in to unmask]
http://www.natehill.net