var data_names;
jQuery.ajax({
type: "POST",
url: 'AutoCompleteHandler.php',
data: {d_name: "d_name"},
dataType: "html",
success: function(data) {
data_names=data;
console.log(data);
}
});
$("#p_name").autocomplete({
minLength: 2,
source:data_names,
focus: function(event, ui) {
$("#p_name").val(ui.item.label);
return false;
},
select: function(event, ui) {
return false;
}
})
.data("ui-autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.append("<a>" + item.label + "/" + item.p_gender + "/" + item.p_age + "</a>")
.appendTo(ul);
};
我尝试使用上面的代码用数据填充我的自动完成框。但是我得到以下错误。当我打印 json 时,我得到了预期的 json。但是当我尝试将它附加到自动完成框时。我得到 json 数组数据并出现以下错误。
[{"0":"kasun","p_name":"kasun","1":"Male","p_gender":"Male","2":"02-01- 1988","p_age":"02-01-1988","3":"880020110v","p_nic":"880020110v"}]
Uncaught TypeError: Property 'source' of object [object Object] is not a function