Mazdak
Mazdak

Reputation: 781

JQuery Autocomplete trouble

I'm trying to recreate JQUery autocomplete example from its website:

http://jqueryui.com/autocomplete/#multiple-remote

The only thing I change is I changes the source property from :

    source: function( request, response ) {
               $.getJSON( "search.php", {
                 term: extractLast( request.term )
               }, response );
             },

To:

source: function (request, response) {
                        $.ajax({
                            type: "POST",
                            url: "/UIClientsWebService.asmx/SearchCRMUsers",
                            data: "{term:'" + extractLast(request.term) + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (result) {
                                $("#commentBody").autocomplete("option", "source", result.d);

                        }
                    }, response);                        

                },

Now the problem is autocomplete just work for first ',' . When I choose my first item, then when I want to search and choose second item, nothing happen. There is no error in my firebug. I can see search method call but source does not change and also nothing shown as my autocomplete items. I can see my search term change correctly but actually no search happen.

Upvotes: 0

Views: 94

Answers (1)

Osama Jetawe
Osama Jetawe

Reputation: 2705

try add the option multiple: true to your script

$(document).ready(function() {
    src = '/UIClientsWebService.asmx/SearchCRMUsers';
    $("#yourSelector").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: src,
                dataType: "json",
                data: "{term:'" + extractLast(request.term) + "'}",
                success: function(data) {
                    response(data);
                }
            });
        },
        min_length: 3,
        delay: 300,
        multipleSeparator:",",
        multiple: true,
    });
});

Upvotes: 3

Related Questions