Skip to content
Permalink
Browse files

Add Awesomplete AJAX function, get list externally

  • Loading branch information...
davidnash committed Mar 13, 2019
1 parent 9a07ee8 commit 25fd3f658e18a5b62ddc255c6cea5b71dfe9923f
Showing with 8 additions and 9 deletions.
  1. +8 −9 js/wp-autocomplete.js
@@ -1,11 +1,10 @@
document.addEventListener('DOMContentLoaded', function() {
console.log('wp-autocomplete.js loaded!');

// Select the <input id="autocomplete-field" /> element in our index.php:
var autocomplete_field = document.getElementById('autocomplete-field');

// Basic Awesomplete demo
new Awesomplete( autocomplete_field, {
list: ["Ada", "Java", "JavaScript", "Node.js", "PHP", "Perl", "Python", "Ruby on Rails"]
});
// Awesomplete AJAX demo from https://leaverou.github.io/awesomplete#ajax-example
var ajax = new XMLHttpRequest();
ajax.open("GET", "https://restcountries.eu/rest/v1/lang/en", true);
ajax.onload = function() {
var list = JSON.parse(ajax.responseText).map(function(i) { return i.name; });
new Awesomplete(document.getElementById("autocomplete-field"),{ list: list });
};
ajax.send();
});

0 comments on commit 25fd3f6

Please sign in to comment.
You can’t perform that action at this time.