awesomplete ajax

raw

phork0.js

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
// https://leaverou.github.io/awesomplete/
  var search = new Awesomplete('#producerdbsearch', {
  minChars: 0,
  });
  document.getElementById('producerdbsearch').addEventListener('input', function() {
      var query = this.value;
      console.log('adf', query);
 
      var xhr = new XMLHttpRequest()
      xhr.open('GET', '/somefoo&q=' + query);
      xhr.onreadystatechange = function() {
          if (xhr.readyState>3 && xhr.status==200) {
              showSearchResults(JSON.parse(xhr.response));
          };
      };
      xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
      xhr.send();
  });
  function showSearchResults(list)
  {
      var newlist = [];
      list.forEach(function(obj) { newlist.push(obj.title);});
      search.list = newlist;
  }
 
 
Christian Weiske Christian Weiske
owner

History