当我使用以下代码从我的网络服务获取时,我无法看到catcomplete自动完成智能感知。我的Web服务返回以下字符串
[{label:"TechCrunch",category:"Website"},{label:"Techcrunch",category:"Tag"}, {label:"techno",category:"Tag"}]
$(document).ready(function() {
$("#<%= txtinputtag.ClientID%>").catcomplete({
source: function(request,response){//error if I hard code this ajax call will with a an array works fine
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../Tag/Follow.aspx/GetIntellisense",
dataType: "json",
data: "{'searchtext':'" + request.term + "'}",
success: function (data) {
if (data.d != "") {
//console.log(data.d);//this show the desired json output as returned from the web service
response(data.d);
}
}
});
},
select: function(event, ui) {
$(this).val("");
return false;
},
});
});
这是返回字符串
的WebMethod [WebMethod]
public static string GetIntellisense(string searchtext)
{
Debugger.Launch();
var uc = new UtilityClass();
List<DTOWebsite> lstDtoWebsites = uc.GetIntellisense(searchtext);
string str = "[";
foreach (DTOWebsite dto in lstDtoWebsites)
{
str += "{label:\""+dto.WebSiteName +"\",category:\""+dto.WebsiteType +"\"},";
}
str = str.Remove(str.Length-1,1);
str += "]";
return str.ToString();
}
答案 0 :(得分:0)
您需要在分配给source
参数的函数中接受2个参数:
request
有term
用于搜索
response
是您将结果传递给
source: function(request, response){ ...