0

Doing jquery autocomplete in the most simple manner, but the results don't get filtered.

html :

<li>
  <div id="vo">
  <input type="text" name="motcle" class="autoMotsCle" value="">
  </div>
</li>

jquery :

$(".autoMotsCle").autocomplete({
source: "motsclef.json"
});

motsclef.json is formated like this :

[
"Arras",
"Bourgogne",
"Brouille",
"Bruges",
"Bruxelles",
"évêque",
"œuvres de loi"
]

Firefox Inspector shows that the term that is sent to the json file is correct : motsclef.json?term=tes

params term = tes but response is the entire json array (1403 responses which is the entirety of the list).

As motsclef.json is formated like this, it didn't seem to me that I would need to do $.getJSON or $.ajax. I don't understand...

1 Answer 1

1

Using this, it will always retrieve all the options because the example shown in page, filters the options in the backend and just retrieves the ones matching the term.

For doing what you want, you could probably do something like:

jQuery.getJSON("motsclef.json", function(data){
  $(".autoMotsCle").autocomplete({
    source: data
  });
});
Sign up to request clarification or add additional context in comments.

Comments

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.