Friday, February 10, 2012

Jquery UI -Autocomplete with Server side data

Good article
Example inside Document.ready
    $('controlname').autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "POST",
                url: "pagename/methodname" , //"search.aspx/getClientNames"
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                // This explicitly disables any browser caching.
                dataFilter: function (data) { return data; },
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            value: item
                        }
                    })) // response
                }, // success
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus);
                }
            }); // ajax
        },
        minLength: 2
    });// autocomplete

No comments:

Post a Comment