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

时间:2014-10-11 17:35:58

标签: javascript c# jquery asp.net ajax

当我使用以下代码从我的网络服务获取时,我无法看到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();
    }

1 个答案:

答案 0 :(得分:0)

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

  1. requestterm用于搜索

  2. response是您将结果传递给

    的回调函数
    source: function(request, response){ ...
    
  3. http://jsfiddle.net/h7uahuhx/