pusatdata

Kode Menampilkan Google Book Cover

Feb 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. HTML:
  2. <head>
  3. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  4. </head>
  5.  
  6. <body>
  7. <section class="media book showcase" data-isbn="0553283685">
  8. <header>
  9. <h3 class="title"></h3>
  10. <h4 class="author"></h4>
  11. <h4 class="publisher"></h4>
  12. </header>
  13. <img src="" alt="" class="thumbnail" />
  14. </section>
  15. <script src="//nla.pusta.cf/tes/books-google.js"></script>
  16. </body>
  17.  
  18. JAVASCRPT >> books-google.js :
  19.  
  20. var isbn = $('.book').data('isbn');
  21. $.ajax({
  22. dataType: 'json',
  23. url: 'https://www.googleapis.com/books/v1/volumes?q=isbn:' + isbn,
  24. success: handleResponse
  25. });
  26. function handleResponse( response ) {
  27. $.each( response.items, function( i, item ) {
  28. var title = item.volumeInfo.title,
  29. author = item.volumeInfo.authors[0],
  30. thumb = item.volumeInfo.imageLinks.thumbnail;
  31. $('.title').text( title );
  32. $('.author').text( author );
  33. $('.thumbnail').attr('src', thumb);
  34. });
  35. }
Add Comment
Please, Sign In to add comment