Reputation: 13233
Trying to first .getJSON
then using that data to become the source of my autocomplete, heres the code.. this isn't working, what am i doing wrong here?
$.getJSON(url, function(data) {
//autocomplete
$(document).ready(function(){
$( "#name" ).autocomplete({
minLength: 2,
source: data
})
});
});
I know i can do source: url
but i don't want to make multiple calls to the jSON data.
Upvotes: 0
Views: 5606
Reputation: 16456
You have to inverse the document ready
event handler to wrap the $.getJSON
aswell:
$(document).ready(function(){
$.getJSON(url, function(data) {
//autocomplete
$( "#name" ).autocomplete({
minLength: 2,
source: data
})
});
});
Also, your data has to be an array. If its JSON, see this for reference: jquery autocomplete with json response
Upvotes: 6