Jquery UI AutoComplete not working with asp.net

不打扰是莪最后的温柔 提交于 2020-01-16 10:29:11

问题


This is my Jquery:

$("#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 };
                }))

            }
        })

    }
});

This is my Main.aspx.cs:

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

    return City;
}

Now this works when i return string instead of List. But when I use it like this with List I get:

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

I don't understand, this solution seem to work to many people on web, maybe it has something to do with my jquery/ui versions? I am using jquery 1.7.1.min and jquery-ui latest version.


回答1:


Change your success function like this

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

Data is contained in data.d property.



来源:https://stackoverflow.com/questions/27578169/jquery-ui-autocomplete-not-working-with-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!