2014-12-20 83 views
0

工作这是我的Jquery:jQuery UI的自动完成不asp.net

$("#completeMe").autocomplete({ 
    source: function (request, response) { 
     $.ajax({ 
      url: "/Main.aspx/GetAutocomplete", 
      type: "POST", 
      dataType: "json", 
      data: Data, 
      contentType: "application/json; charset=utf-8", 
      success: function (data) { 
       response($.map(data, function (item) { 
        return { value: item }; 
       })) 

      } 
     }) 

    } 
}); 

这是我Main.aspx.cs:

[System.Web.Services.WebMethod] 
public static List<string> GetAutocomplete(string cityName) 
{ 
    List<string> City = new List<string>() { "hh", "hh1" }; 

    return City; 
} 

现在这个工程时,我不是返回列表的字符串。但是,当我使用它像这样用列表我得到:

Uncaught TypeError: undefined is not a function jquery-ui.min.js:9...

我不明白,这个方案似乎工作的许多人在网上,也许有事情做与我的jquery/UI版本?我正在使用jquery 1.7.1.min和jquery-ui最新版本。

+0

可能值得一看你从WebMethod得到的回应;在浏览器中使用开发人员控制台,通常通过按F12键激活。 –

回答

3

更改成功函数这样

success: function (data) { 
      response($.map(data.d, function (item) { 
       return { value: item }; 
      })) 

数据包含在data.d财产。

+0

作品,ty,我的不好 – user3770158

+0

@MairajAhmad:不错,需要向你学习Ajax。 +1进行清晰的解释。 'data.d'属性 – BNN