Created
May 5, 2018 12:26
-
-
Save kubawich/2df43c0e2e79dc12332fb6e8a9c6af04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get all books | |
function GetAll() { | |
let xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function () { | |
if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4 | |
if (xmlhttp.status == 200) { | |
let x = JSON.parse(xmlhttp.responseText); | |
PutToTable(Object.keys(x).length, x); | |
} | |
} | |
}; | |
xmlhttp.open("GET", 'http://localhost:51195/api/library/api/library/get/library', true); | |
xmlhttp.send(); | |
} | |
window.onload = GetAll | |
function PutToTable(max, x) { | |
for (var i = 0; i < max; i++) { | |
document.getElementById('database').innerHTML = `<tr><td>${x[i].title}</td><td>${x[i].author}</td><td>${x[i].year}</td><td>${x[i].pages}</td></tr>` | |
console.log(x[i].title); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment