I want to populate my autocomplete with data from database.
So I wrote a method in c# to read it from db:
public string[] GetNames()
{
var names = unitOfWork.deviceRepository.Get().Select(w=>w.Name);
return names.ToArray();
}
And this works just fine. All needed data is in names.
Now Ajax I'm using to get this data to client side:
$(function () {
var availableTags;
$.ajax({
url: "/DeviceUsage/GetNames",
type: "GET",
error: function (data) {
alert("wystąpił nieokreślony błąd " + data);
},
success: function (data) {
console.log(data);
availableTags = data;
}
})
$("#deviceName").autocomplete({
source: availableTags
});
});
As You can see I'm leaving dataType for intelligent guess.
But the console.log in success writes System.String[] in console instead of data from GetNames.
Can anyone suggest me how to modify my code to get the autocomplete work?