0

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 this 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, but the autocomplete is not suggesting anything.

1
  • (The blog link herein may be restored, but it is presently dead. The hosting company says "This domain name expired on 2/5/2018 and is pending renewal or deletion". Perhaps if it is still unavailable in a couple of months, we can remove it from this question). Commented Feb 28, 2018 at 14:57

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

. 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 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: jqueryui.com/demos/autocomplete/#multiple-remote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.