Skip to content

Instantly share code, notes, and snippets.

@kubawich
Created May 5, 2018 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubawich/2df43c0e2e79dc12332fb6e8a9c6af04 to your computer and use it in GitHub Desktop.
Save kubawich/2df43c0e2e79dc12332fb6e8a9c6af04 to your computer and use it in GitHub Desktop.
//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