2014-12-20 81 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