Monday, 9 September 2013

Load a file into array for JQuery widget autocomplete

Load a file into array for JQuery widget autocomplete

trying to implement this http://jqueryui.com/autocomplete/ but by loading
the array from a txt file with values on each line
what I have
<script>
$(function() {
var availableTags = new Array();
$.get('sample.txt', function(data){
availableTags = data.split('\n');
console.log(availableTags);
});
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
The console shows a correct array but the auto complete does not work.
Using the same values in an array auto complete works but not if those
values are loaded from a file.

No comments:

Post a Comment