I do not know what is wrong with this code. alert shows that data has returned from web service but auto-complete still not showing data. I am using ASP.net 2.0 and google jquery link
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://localhost/WebService/Service.asmx/getlist2",
dataType: "json",
data: "{}",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert("getlist 2");
alert(data);
$('#project1').autocomplete({
minLength: 2,
source: data,
focus: function(event, ui) {
$('#project1').val(ui.item.TagName);
alert(ui.item.TagName);//no alert is fired here
return false;
},
select: function(event, ui) {
$('#project1').val(ui.item.TagName);
//$('#selectedValue').text("Selected value:" + ui.item.TagID);
return false;
}
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
});
and web service method
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Tag> getlist2()
{
<Tag> tagscollection = new EntitiesCollection<Tag>();
ProcessTagList getlisttags = new ProcessTagList();
string strtag = "";
Tag tag = new Tag();
tag.TagName = strtag;
tag.UniqueName = strtag;
getlisttags.OTag = tag;
getlisttags.Invoke();
tagscollection = getlisttags.OTagsCollection;
;
List<Tag> a = new List<Tag>();
foreach(Tag tagc in tagscollection)
{
a.Add(tagc);
}
return a;
}
data shown in firebug is:
[{"__type":"myproject.Common.Tag","TagID":"21abf6b1-6d45-41e5-a39b-006e621eeb22","UniqueName":"dotnet","TagName":"dotnet","CreatedAt":"\/Date(1255108286850)\/"}]
this jquery code shows dropdown list from the webservice used with first jquery example.
$("#tbAuto").autocomplete({
source: function(request, response) {
$.ajax({
url: "http://localhost/myproject/Service.asmx/getlist2",
data: "{}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
// dataFilter: function(data) { return data; },
success: function(data) {
response($.map(data, function(item) {
return {
value: item.TagName
}
}))
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorTrown);
}
});
},
minLength: 0
});