Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html class="no-js">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>Kol 2 grupa 1</title>
  7. <meta name="description" content="">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <link rel="stylesheet" href="">
  10. <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  11. </head>
  12. <body>
  13. <input type="text" id="IsbnCode" placeholder="Enter your ISBN here:"/>
  14. <button type="button" id="AddBook">
  15. Add Book
  16. </button>
  17. <ol id="BooksList">
  18. </ol>
  19. </body>
  20. <script type="text/javascript">
  21. var book;
  22. var bookArray = [];
  23. $(document).ready( function(){
  24. $("#AddBook").on('click',function(){
  25. var isbn = $("#IsbnCode").val();
  26. if(isbn.length == 10 || isbn.length == 13)
  27. {
  28. var apiUrl = "https://openlibrary.org/api/books?bibkeys="+ isbn +"&jscmd=details&format=json";
  29. //Test ISBN: 9780605039070
  30. if(!bookArray.includes(isbn))
  31. $.ajax({
  32. type: 'GET',
  33. url: apiUrl,
  34. datatype: 'json'
  35. }).always(function(data){
  36. console.log(data);
  37. book = data[isbn];
  38. $("#BooksList").append("<li> <ul id="+isbn+">"+ book.details.title +" <li>"+ book.details.isbn_13 +"</li><li><img src="+ book.preview_url +"/></li><li>"+ book.info_url +"</li><ul></li>");
  39. $("#"+isbn+" > li").hide();
  40. $("#"+isbn).bind('click',function(){
  41. $("#"+isbn+" > li").toggle();
  42. });
  43. bookArray.push(isbn);
  44. });
  45. }
  46. });
  47. });
  48. </script>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement