user560498
user560498

Reputation: 547

jquery ui autocomplete and json call

I'm trying to implement autocomplete for a textbox using the following code, but it's not working: (The ajax call to MyUrl works fine and returns a json string made of List of strings)

$(document).ready(function () {
    $(".searchbox").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/MyUrl/" + request.term.toLowerCase(),
                dataFilter: function (data) { return data; },
                success: function (data) {
                    return data;
                }
            });

        },
        minLength: 1
    });
});

Is this call correct ?

Upvotes: 1

Views: 601

Answers (1)

David Hedlund
David Hedlund

Reputation: 129832

You're not supposed to return the data, you're supposed to pass it to the response callback.

success: function(data) {
    response(data);
}

Which is pretty much the same thing as:

success: response

Upvotes: 4

Related Questions