0

I am not seeing data returned from my webservice using the JQuery Autocomplete plugin.

Im sure that this is an issue with the JQuery part of my code. (Firebug shows that I am getting a string back from my webservice formatted like below.)

"[\"Component 1\",\"Component 2\",\"Component 2\",\"Component 3\"]"

(I did assume that it might be the fact that there were 2 items the same, but removing the duplicate made no difference.)

my JQuery code is...

 $('#tags').autocomplete({             
                            source: function (request, response) {
                                    $.ajax({
                                            type: "POST",
                                            contentType: "application/json; charset=utf-8",
                                            url: "QuickSearch/QuickSearch.asmx/GetDealerships",
                                            data: "{'s':'" + request.term + "'}",
                                            dataType: "json",
                                            async: true,
                                            success: function (data){
                                                    response(data.d);
                                                },
                                                error: function (result) {
                                                        alert("Due to unexpected errors we were unable to load data");
                                                    }
                                });
                    },
        minLength: 2
                });
        });

So can anyone tell me what I have wrong in the success: function ?

Thanks

Edit

    var array = data.split(",");
    response(array);

The above code almost works, except my drop down box also has the " symbols wrapping each element. I can edit this to strip out the spare characters, but the fact that I am having to do that makes me suspect I havent got it quite right somewhere..

4

1 回答 1

0

将此脚本用于成功事件处理程序:

response($.map(data, function (item) {
     return { label: item, value: item };
}));

更多信息:http: //api.jqueryui.com/autocomplete/#event-response

于 2012-10-17T14:49:37.827 回答