jquery - Cannot get json data from ajax request to display in html -
i trying use new york times bestseller list api list current top 20 in html - i've managed retrieve data using ajax (i can see using developer tools) have got stuck trying display on page. don't error messages - nothing happens. code is:
<!doctype html> <html> <head> <title>discover books</title> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <meta charset="utf-8"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.js"></script> <div id='books'> </div> </head> <script> $(document).ready(function(){ $.ajax ({ type: 'get', datatype: 'json', url: 'http://api.nytimes.com/svc/books/v3/lists/hardcover-fiction?api-key=*api_key*', success: function(response){ console.log(response); for(var = 0; < response.length; i++) { var listing = response[i]; $('#books').append('<h3>' + title + '</h3>'); } }, error: function(xhr, status, error){ console.log(status); console.log(error); } }); }) </script> </html> any hints i'm doing wrong? thanks
title undefined in success function. should refer listing.title.
success: function(response){ console.log(response); for(var = 0; < response.length; i++) { var listing = response[i]; $('#books').append('<h3>' + listing.title + '</h3>'); } } and looking @ api response, need drill down json bit books.
success: function(response){ console.log(response); books = response.results.books; //you may need tinker for(var = 0; < books.length; i++) { var listing = books[i]; $('#books').append('<h3>' + listing.title + '</h3>'); } }
Comments
Post a Comment