Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. function getComments() {
  2. uri = "http://localhost:8188/Service.svc/htmlcomments";
  3. var xhr = new XMLHttpRequest();
  4. xhr.open("GET", uri, true);
  5. xhr.onload = function () {
  6. var resp = (xhr.responseText);
  7. document.getElementById("addComments").innerHTML = xhr.responseText;
  8. }
  9. xhr.send(null);
  10. }
  11.  
  12. function comment() {
  13. var Name = document.getElementById("name").value;
  14. var Feedback = document.getElementById("feedback").value;
  15. uri = "http://localhost:8188/Service.svc/comment?name=" + Name;
  16. var xhr = new XMLHttpRequest();
  17. xhr.open("POST", uri, true);
  18. xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  19. xhr.send(JSON.stringify(Feedback));
  20.  
  21. getComments()
  22. }
  23.  
  24. function buyBook(id) {
  25. window.location.href = "http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/bookbuy?id=" + id;
  26. }
  27.  
  28. function buyBluray(id) {
  29. var uri = "http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/brbuy?id=" + id;
  30. window.location.href = uri;
  31. }
  32.  
  33. function register() {
  34. var Password = document.getElementById("password").value;
  35. var Username = document.getElementById("username").value;
  36. var Address = document.getElementById("address").value;
  37. uri = "http://localhost:8188/Service.svc/register";
  38. var xhr = new XMLHttpRequest();
  39. xhr.onreadystatechange = function() {
  40. if (xhr.readyState == 4 && xhr.status == 200) {
  41. document.getElementById("signUp").innerHTML += xhr.responseText;
  42. }
  43. }
  44. xhr.open("POST", uri, true);
  45. xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  46. xhr.send(JSON.stringify({"Address":Address, "Name":Username, "Password":Password}));
  47. }
  48.  
  49. function checkEnter(e) {
  50. if (e.keyCode == 13) booksOrBluray(document.getElementById('search').value);
  51. }
  52. function showBooks(dest) {
  53. var listContent = "";
  54. for (var i = 0; i < dest.length; ++i) {
  55. var record = dest[i];
  56. var id = "" + record.Id;
  57. var button = "<button class='right' type='button' onclick='window.location.href = \"http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/bookbuy?id=" + id + "\"'>Buy Now!</button>"
  58. var img = "<img alt='Logo' src='http://localhost:8188/Service.svc/bookimg?id="
  59. + record.Id + "' style='max-width: 200px; width: 100%; display: inline-block; vertical-align: middle;' />"
  60. listContent += "<tr><td>" + img + "</td><td class='mid'>" + record.Title +
  61. "</td><td>" + button + "</td></tr>";
  62. }
  63. if (listContent == "") listContent += "<br>no results.<br>"
  64. document.getElementById("showTab").innerHTML = listContent;
  65. }
  66.  
  67. function getBluray(uri) {
  68. uri = uri || "http://localhost:8188/Service.svc/brlist";
  69. var xhr = new XMLHttpRequest();
  70. xhr.open("GET", uri, true);
  71. xhr.setRequestHeader('Accept', 'application/json');
  72. xhr.onload = function () {
  73. var resp = JSON.parse(xhr.responseText);
  74. showBluray(resp);
  75. }
  76. xhr.send(null);
  77. }
  78.  
  79. function showBluray(dest) {
  80. var listContent = "";
  81. for (var i = 0; i < dest.length; ++i) {
  82. var record = dest[i];
  83. var id = record.Id;
  84. var button = "<button class='right' type='button' onclick='window.location.href = \"http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/brbuy?id=" + id + "\"'>Buy Now!</button>"
  85. var img = "<img alt='Logo' src='http://localhost:8188/Service.svc/brimg?id="
  86. + record.Id + "' style='max-width: 200px; width: 100%; display: inline-block; vertical-align: middle;' />"
  87. listContent += "<tr><td>" + img + "</td><td class='mid'>" + record.Title +
  88. "</td><td>" + button + "</td></tr>";
  89. }
  90. if (listContent == "") listContent += "<BR><BR>no results.<BR><BR>"
  91. document.getElementById("showTab").innerHTML = listContent;
  92. }
  93. function booksOrBluray(search) {
  94. search = search || null;
  95. var a = document.getElementById("mySelect").value;
  96. if (a == "Books") {
  97. if (search == null || search == "") getBooks();
  98. else getBooks("http://localhost:8188/Service.svc/booksearch?term=" + search);
  99. }
  100. else if (a == "Bluray") {
  101. if (search == null || search == "") getBluray();
  102. else getBluray("http://localhost:8188/Service.svc/brsearch?term=" + search);
  103. }
  104. }
  105.  
  106. function getBooks(uri) {
  107. uri = uri || "http://localhost:8188/Service.svc/booklist";
  108. var xhr = new XMLHttpRequest();
  109. xhr.open("GET", uri, true);
  110. xhr.setRequestHeader('Accept', 'application/json');
  111. xhr.onload = function () {
  112. var resp = JSON.parse(xhr.responseText);
  113. showBooks(resp);
  114. }
  115. xhr.send(null);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement