function search(searchfield) { txt = searchfield.value; if (txt == "") { reallyclear() } else { xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = searchresult xhttp.open("GET","/db/search?max=5&query=" + encodeURIComponent(txt), true); xhttp.send(); } } function searchresult() { if (this.readyState == 4 && this.status == 200 && document.getElementById("searchinput").value != "") { // checking if field is empty in case we get an old result coming in that would overwrite our cleared result window result = JSON.parse(this.responseText); artists = result["artists"].slice(0,5) tracks = result["tracks"].slice(0,5) html = `
` + name + ` |
`
}
html += `
` + artists + ` ` + title + ` |