Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Awesomplete AJAX function, get list externally
- Loading branch information
Showing
1 changed file
with
8 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | ||
}); | |||
}); | }); |