0

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
  • Probably worth looking at the response you get from your WebMethod; use the developer console in your browser, usually activated by pressing the F12 key. Commented Dec 20, 2014 at 7:51

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@MairajAhmad: Nice one, need to learn Ajax from you. +1 for the clear explanation. of data.d property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.