i'm trying to do a jquery ui autocomplete with some countries i get from db with an ajax call
I'm struggling on how to pass my table of values to the autocomplete
$( document ).ready(function() {
$.ajax({
url:Routing.generate('e_veilleur_user_register_countries_autocomplete'),
type:"get",
dataType: 'json',
data: 'test=cool',
async: true,
cache: true,
success: function(data){
var availableTags = data;
}
});
$( "#fos_user_registration_form_pays" ).autocomplete({
source: availableTags
});
});
The result of my ajax call is
[{"countryName":"United States"},
{"countryName":"Canada"},
{"countryName":"Afghanistan"},
{"countryName":"Albania"},
{"countryName":"Algeria"}
Error given : availableTags is not defined
availableTagsbefore the AJAX completes. jQuery Autocomplete allows you to specify an AJAX URL in thesource:option, use that.