Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getComments() {
- uri = "http://localhost:8188/Service.svc/htmlcomments";
- var xhr = new XMLHttpRequest();
- xhr.open("GET", uri, true);
- xhr.onload = function () {
- var resp = (xhr.responseText);
- document.getElementById("addComments").innerHTML = xhr.responseText;
- }
- xhr.send(null);
- }
- function comment() {
- var Name = document.getElementById("name").value;
- var Feedback = document.getElementById("feedback").value;
- uri = "http://localhost:8188/Service.svc/comment?name=" + Name;
- var xhr = new XMLHttpRequest();
- xhr.open("POST", uri, true);
- xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- xhr.send(JSON.stringify(Feedback));
- getComments()
- }
- function buyBook(id) {
- window.location.href = "http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/bookbuy?id=" + id;
- }
- function buyBluray(id) {
- var uri = "http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/brbuy?id=" + id;
- window.location.href = uri;
- }
- function register() {
- var Password = document.getElementById("password").value;
- var Username = document.getElementById("username").value;
- var Address = document.getElementById("address").value;
- uri = "http://localhost:8188/Service.svc/register";
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4 && xhr.status == 200) {
- document.getElementById("signUp").innerHTML += xhr.responseText;
- }
- }
- xhr.open("POST", uri, true);
- xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- xhr.send(JSON.stringify({"Address":Address, "Name":Username, "Password":Password}));
- }
- function checkEnter(e) {
- if (e.keyCode == 13) booksOrBluray(document.getElementById('search').value);
- }
- function showBooks(dest) {
- var listContent = "";
- for (var i = 0; i < dest.length; ++i) {
- var record = dest[i];
- var id = "" + record.Id;
- 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>"
- var img = "<img alt='Logo' src='http://localhost:8188/Service.svc/bookimg?id="
- + record.Id + "' style='max-width: 200px; width: 100%; display: inline-block; vertical-align: middle;' />"
- listContent += "<tr><td>" + img + "</td><td class='mid'>" + record.Title +
- "</td><td>" + button + "</td></tr>";
- }
- if (listContent == "") listContent += "<br>no results.<br>"
- document.getElementById("showTab").innerHTML = listContent;
- }
- function getBluray(uri) {
- uri = uri || "http://localhost:8188/Service.svc/brlist";
- var xhr = new XMLHttpRequest();
- xhr.open("GET", uri, true);
- xhr.setRequestHeader('Accept', 'application/json');
- xhr.onload = function () {
- var resp = JSON.parse(xhr.responseText);
- showBluray(resp);
- }
- xhr.send(null);
- }
- function showBluray(dest) {
- var listContent = "";
- for (var i = 0; i < dest.length; ++i) {
- var record = dest[i];
- var id = record.Id;
- 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>"
- var img = "<img alt='Logo' src='http://localhost:8188/Service.svc/brimg?id="
- + record.Id + "' style='max-width: 200px; width: 100%; display: inline-block; vertical-align: middle;' />"
- listContent += "<tr><td>" + img + "</td><td class='mid'>" + record.Title +
- "</td><td>" + button + "</td></tr>";
- }
- if (listContent == "") listContent += "<BR><BR>no results.<BR><BR>"
- document.getElementById("showTab").innerHTML = listContent;
- }
- function booksOrBluray(search) {
- search = search || null;
- var a = document.getElementById("mySelect").value;
- if (a == "Books") {
- if (search == null || search == "") getBooks();
- else getBooks("http://localhost:8188/Service.svc/booksearch?term=" + search);
- }
- else if (a == "Bluray") {
- if (search == null || search == "") getBluray();
- else getBluray("http://localhost:8188/Service.svc/brsearch?term=" + search);
- }
- }
- function getBooks(uri) {
- uri = uri || "http://localhost:8188/Service.svc/booklist";
- var xhr = new XMLHttpRequest();
- xhr.open("GET", uri, true);
- xhr.setRequestHeader('Accept', 'application/json');
- xhr.onload = function () {
- var resp = JSON.parse(xhr.responseText);
- showBooks(resp);
- }
- xhr.send(null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement