Advertisement
Nazukai

Untitled

Dec 3rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Insert title here</title>
  6. </head>
  7. <body>
  8. <div id="bookInfo"></div>
  9. <script>
  10.  
  11.  
  12. function GetURLParameter(sParam)
  13. {
  14. var sPageURL = window.location.search.substring(1);
  15. var sURLVariables = sPageURL.split('&');
  16. for (var i = 0; i < sURLVariables.length; i++)
  17. {
  18. var sParameterName = sURLVariables[i].split('=');
  19. if (sParameterName[0] == sParam)
  20. {
  21. return sParameterName[1];
  22. }
  23. }
  24. }
  25.  
  26.  
  27. fetch('http://localhost:8080/rest/books/'+GetURLParameter('id'))
  28. .then(function (response) {
  29.  
  30. return response.json();
  31. })
  32. .then(function (data) {
  33. id = data.id;
  34. appendData(data);
  35. })
  36. .catch(function (err) {
  37. console.log(err);
  38. });
  39.  
  40. function appendData(data) {
  41. var text = "";
  42. text += "<div class="info" id="info">";
  43. text += "<h1>"+"<strong>Ttile:"+data.title + "</strong> </h1>";
  44. //text += "<strong>Post By: </strong>"+data.owner.username;
  45. text+= "<br/>";
  46. text += "<strong>Author: </strong>"+data.author;
  47. text+= "<br/>";
  48. text += "<strong>Release date: </strong>"+data.year;
  49. text+= "<br/>";
  50. text += "<strong>Rate: </strong>"+data.rating;
  51. text+= "<br/>";
  52.  
  53.  
  54. document.getElementById("bookInfo").innerHTML = text;
  55. }
  56.  
  57. </script>
  58.  
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement