Skip to content

Commit

Permalink
Add Awesomplete AJAX function, get list externally
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnash committed Mar 13, 2019
1 parent 9a07ee8 commit 25fd3f6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions js/wp-autocomplete.js
@@ -1,11 +1,10 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
console.log('wp-autocomplete.js loaded!'); // Awesomplete AJAX demo from https://leaverou.github.io/awesomplete#ajax-example

var ajax = new XMLHttpRequest();
// Select the <input id="autocomplete-field" /> element in our index.php: ajax.open("GET", "https://restcountries.eu/rest/v1/lang/en", true);
var autocomplete_field = document.getElementById('autocomplete-field'); ajax.onload = function() {

var list = JSON.parse(ajax.responseText).map(function(i) { return i.name; });
// Basic Awesomplete demo new Awesomplete(document.getElementById("autocomplete-field"),{ list: list });
new Awesomplete( autocomplete_field, { };
list: ["Ada", "Java", "JavaScript", "Node.js", "PHP", "Perl", "Python", "Ruby on Rails"] ajax.send();
});
}); });

0 comments on commit 25fd3f6

Please sign in to comment.