I need to supply my autocomplete from a webservice who passes an array into the autocomplete source.
Here is my webservice:
public Filter[] getAutoComplete(string column)
{
List<Filter> list = new List<Filter>();
DbAccess dbacc = new DbAccess();
DataTable dt = dbacc.getColumnHeader(column);
Filter _Filter = new Filter();
if (column == "member_id")
{
foreach (DataRow row in dt.Rows)
{
_Filter.memid = row["member_id"].ToString();
}
}
else if (column == "lname")
{
foreach (DataRow row in dt.Rows)
{
_Filter.memid = row["lname"].ToString();
}
}
else if (column == "mname")
{
foreach (DataRow row in dt.Rows)
{
_Filter.memid = row["mname"].ToString();
}
}
else if (column == "fname")
{
foreach (DataRow row in dt.Rows)
{
_Filter.memid = row["fname"].ToString();
}
}
list.Add(_Filter);
return list.ToArray();
}
And here is my jquery ajax:
$.ajax({
url: "webservices/wbFilters.asmx/getAutoComplete",
data: json,
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (mydata) {
$("#tags").autocomplete({
source: mydata
});
}
});
I can verify that my list array has a value. I just couldn't attach it to my autocomplete. I read that I can add a array as a source but I really can't get it to work.
Can someone please explain what needs to be done to get this working?