blob: 0f544ab9f6a1d4f0b09c53223c3b8ce15ea6afe1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
var strokeTimeout = null;
function instantSearch() {
value = document.getElementById("search").value;
if (strokeTimeout) {
clearTimeout(strokeTimeout);
}
strokeTimeout = setTimeout(doSearch, 150, value);
}
function doSearch(value) {
if (value == "") {
strokeTimeout = null;
return;
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined') {
console.log(xhr.status);
document.getElementById("search-results").innerHTML = '';
}
document.getElementById("search-results").innerHTML = xhr.response;
}
}
console.log(value);
xhr.open('GET', '/search/gril_instant/' + value, true);
xhr.send(null);
strokeTimeout = null;
}
|