gpt4 book ai didi

javascript - Jquery Autocomplete()/Catcomplete() 函数不起作用

转载 作者:行者123 更新时间:2023-11-28 07:54:13 24 4
gpt4 key购买 nike

当我使用下面的代码从我的网络服务中获取 catcomplete 自动完成智能感知时,我无法看到它。我的网络服务返回以下字符串

[{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();
}

最佳答案

您需要在函数中接受 2 个分配给 source 参数的参数:

  1. 请求具有搜索的术语

  2. response 是您将结果传递给的回调函数

    source: function(request, response){ ...

http://jsfiddle.net/h7uahuhx/

关于javascript - Jquery Autocomplete()/Catcomplete() 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26317359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com