Hey, folks. I'm pretty new to jQuery and javascript in general and I'm having a bit of trouble with the Autocomplete widget found in jQuery-ui.
I'm trying to get a whole bunch of JSON data which I have pulled from a mySQL database and formatted with PHP in a rather specific way. I then want to format portions of this data into an array which is then used as the source for the autocomplete widget.
Here is the autocomplete bit:
var dogs = [];
$( '.dogs' ).autocomplete({
source: dogs,
delay: 10,
});
Pretty basic, and I can get it to work as expected. When I start in with the Ajax is when things get confusing.
My JSON data is formatted "0":{"actu":"Actual Name0","disp":"Display Name0"},"1":{"actu":"Actual Name1","disp":"Display Name1"}, etc. such that each 'dog' has two names and a unique, numerical ID to make it easier to loop through the data.
var dogNames = [];
$.getJSON("dataconditioner.php", function(json) {
for (var k in json){
dogNames[k] = json[k]["disp"];
}
$( '.dog' ).autocomplete( "option", "source", dogNames);
});
The goal here is to get all of the display names into a 1D array and then have the autocomplete use that array as its source. The array seems formed correctly as when I use alert() to print out results within the callback, I get the expected results. But for whatever reason the autocomplete does nothing when I use this array as its source.
Thanks in advance.