document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#form').onsubmit = () => {
var search = document.querySelector('#search').value;
makeXHR('POST', '/booklist', search).then(showBookList, errorHandler);
}
});
function showBookList(data) {
document.querySelector('.result').innerHTML = "";
for (let i = 0; i < data.length; i++)
{
var newA = document.createElement('a')
newA.className = "show"
var newD = document.createElement('div')
var newH2 = document.createElement('h2')
var newH3 = document.createElement('h3')
newH2.innerHTML = data[i].title;
newH3.innerHTML = data[i].author;
newD.className = 'book'
newD.appendChild(newH2)
newD.appendChild(newH3)
newA.appendChild(newD)
document.querySelector('.result').appendChild(newA);
}
}
function errorHandler(status) {
alert('Process failed whith status ', status);
}