views:

27

answers:

1

Hi All,

I am trying to use the JqueryUI autocomplete plugin but I am unable to make it work.

I am using Spring MVC at the backend and I am returning JSON response by following this http://loianegroner.com/2010/02/spring-mvc-and-ajax-with-json/ post that I got from the net.

My problem is, there seem to be some problem in the way the autocomplete plugin expects the JSON response. I checked on my firebug and it is displaying below JSON response.

{"data":["TEST-01","TEST-02","TEST-03"]}

No error is being thrown out but the autocomplete is not suggesting anything.

Any pointers please?

Thanks all..

+2  A: 

Why don't you consult official jquery-ui documentation about expected response format?

In short, valid response could look like this

[{'label': 'TEST-01'}, {'label': 'TEST-02'}, {'label': 'TEST-03'}]

More from the docs
data can be a simple Array of Strings, or it contains Objects for each item in the array, with either a label or value property or both. The label property is displayed in the suggestion menu. The value will be inserted into the input element after the user selected something from the menu. If just one property is specified, it will be used for both, eg. if you provide only value-properties, the value will also be used as the label.

Nikita Rybak
@nikita.. I actually dont know how the library that I got from the net is converting the JSON response. I just want to know, if I could configure the autocomplete ui to parse the JSON response. Is this possible to do wherein I can change how the jquery ui is parsing the response?
Mark Estrada
@Mark Check docs: you can pass function instead of url as 'source' option. There you can make ajax request and parse data in whatever way you need. Here's one example: http://jqueryui.com/demos/autocomplete/#multiple-remote
Nikita Rybak