Reputation: 326
autocomplete inside ajax not working...help
$.ajax({
url: 'url',
type: 'GET',
dataType :'jsonp',
async: false,
crossDomain:true,
success: function(data) {
var resp = data.response;
var availableTags="[";
for (i = 0; i <= 10; i++) {
var postSub = resp.messages.message[i].subject.$;
if (i < 10) {
availableTags += postSub + ",";
}
else {
availableTags += postSub;
}
}
availableTags += "]";
$("#tags").autocomplete({
source: availableTags
});
}
});
Upvotes: 1
Views: 623
Reputation: 25527
It wont populate because availableTags is a string, not array type. You should make it as an array. Change your code like,
var availableTags = "[";
for (i = 0; i <= 10; i++) {
var postSub = resp.messages.message[i].subject.$;
if (i < 10) {
availableTags +="\"" +postSub + "\",";
}
else {
availableTags +="\""+ postSub+"\"";
}
}
availableTags += "]";
availableTags=eval(availableTags);
Upvotes: 1
Reputation: 337560
You don't need to make the AJAX request yourself, as the source
parameter takes a URL as a string and will do all of this for you. Try this:
$("#tags").autocomplete({
source: 'yourURL'
});
Upvotes: 0