diff options
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/search.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/assets/js/search.js b/assets/js/search.js index 0f544ab..ebf46cb 100644 --- a/assets/js/search.js +++ b/assets/js/search.js | |||
@@ -1,30 +1,29 @@ | |||
1 | var strokeTimeout = null; | 1 | var strokeTimeout = null; |
2 | 2 | ||
3 | function instantSearch() { | 3 | function instantSearch() { |
4 | value = document.getElementById("search").value; | ||
5 | |||
6 | if (strokeTimeout) { | 4 | if (strokeTimeout) { |
7 | clearTimeout(strokeTimeout); | 5 | clearTimeout(strokeTimeout); |
8 | } | 6 | } |
9 | strokeTimeout = setTimeout(doSearch, 150, value); | 7 | strokeTimeout = setTimeout(doSearch, 150, value); |
10 | } | 8 | } |
11 | 9 | ||
12 | function doSearch(value) { | 10 | function doSearch() { |
13 | if (value == "") { | 11 | value = document.getElementById("search").value; |
12 | |||
13 | if (value === "") { | ||
14 | strokeTimeout = null; | 14 | strokeTimeout = null; |
15 | return; | 15 | return; |
16 | } | 16 | } |
17 | var xhr = new XMLHttpRequest(); | 17 | var xhr = new XMLHttpRequest(); |
18 | xhr.onreadystatechange = function() { | 18 | xhr.onreadystatechange = function() { |
19 | if (xhr.readyState == XMLHttpRequest.DONE) { | 19 | if (xhr.readyState == XMLHttpRequest.DONE) { |
20 | if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined') { | 20 | if (xhr.status === 404 || xhr.status === 400 || typeof xhr.response === 'undefined' || xhr.response === '404 not found') { |
21 | console.log(xhr.status); | ||
22 | document.getElementById("search-results").innerHTML = ''; | 21 | document.getElementById("search-results").innerHTML = ''; |
22 | return | ||
23 | } | 23 | } |
24 | document.getElementById("search-results").innerHTML = xhr.response; | 24 | document.getElementById("search-results").innerHTML = xhr.response; |
25 | } | 25 | } |
26 | } | 26 | } |
27 | console.log(value); | ||
28 | xhr.open('GET', '/search/gril_instant/' + value, true); | 27 | xhr.open('GET', '/search/gril_instant/' + value, true); |
29 | xhr.send(null); | 28 | xhr.send(null); |
30 | strokeTimeout = null; | 29 | strokeTimeout = null; |