简体   繁体   中英

Jquery UI AutoComplete not working with asp.net

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM