Jquery Autocomplete()/Catcomplete()函数不起作用
Jquery Autocomplete() / Catcomplete() Function not working
当我使用以下代码从web服务中获取catcomplete自动完成intellisense时,我无法看到它。我的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();
}
您需要在分配给source
参数的函数中接受两个参数:
-
request
具有用于搜索的term
-
response
是将结果传递给的回调函数source: function(request, response){ ...
http://jsfiddle.net/h7uahuhx/
相关文章:
- Ember Data DS.Model's set函数不起作用
- 为什么我的JavaScript堆栈排序函数不起作用
- Javascript onchange()函数不起作用
- 另一个Ajax函数触发的Ajax函数不起作用
- 从PHP调用JS函数不起作用
- jQuery validate函数不起作用
- JS-窗口宽度函数不起作用
- javascript函数,该函数不起作用,但不会显示任何错误
- 为什么这个排序函数不起作用
- 为什么这个反向函数不起作用
- Javascript parseInt 函数不起作用
- 我的函数不起作用,Ajax调用,JQuery,调用外部?我不知道
- 主干构造函数不起作用
- Javascript:this.value 函数不起作用
- Mocha 的 beforeEach() 和 done() 函数不起作用
- 在jQuery中,我的函数不起作用
- jquery-ui-rails的draggable和dropable函数不起作用
- 数学函数不起作用
- Javascript-创建打印到HTML的函数不起作用
- 我上传了客户's服务器一个js函数不起作用