Reputation: 45
I ma using jquery UI auto complete and i am getting the results, the only problem i am getting the results
not sure why it is not display, the json
is coming as correct
my JSOn
[{"name":"author","type":"U","status":"0","owner":"dbo"},{"name":"author_dates","type":"U","status":"0","owner":"dbo"}]
$("#student").autocomplete(
{
source: function(request, response) {
$.ajax({
url: "search.cfc?method=searchByName&returnformat=json",
dataType: "json",
data: {
search: request.term,
maxRows: 10
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.label, value: item.label
};
}));
}
})
},
select: function( event, ui ) {
$('#submit').css("display", "block");
}
});
Upvotes: 0
Views: 37
Reputation: 30893
Please consider the following:
$("#student").autocomplete({
source: function(request, response) {
$.getJSON("search.cfc", {
method: "searchByName",
returnformat: "json",
search: request.term,
maxRows: 10
}, function(data) {
response($.map(data, (item) => {
return $.extend(item, {
label: item.name,
value: item.name,
});
}));
});
},
select: function(event, ui) {
$('#submit').css("display", "block");
}
});
Upvotes: 1
Reputation: 17610
Your object attribute is name, not label so u should write name despide of label
$("#student").autocomplete(
{
source: function(request, response) {
$.ajax({
url: "search.cfc?method=searchByName&returnformat=json",
dataType: "json",
data: {
search: request.term,
maxRows: 10
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.name, value: item.name
};
}));
}
})
},
select: function( event, ui ) {
$('#submit').css("display", "block");
}
});
Upvotes: 1