autocompete with ajax
See original GitHub issueIs possible use autocompete plugin with ajax? For data load from server, something like this (but not woking):
$.ajax({
url: $this.attr('data-url'),
method: 'post',
data: {
city: $this.val()
},
dataType: 'json',
success: function (res) {
if (res != false) {
$this.autocomplete({
data: res
});
}
}
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:29 (1 by maintainers)
Top Results From Across the Web
jQuery AJAX Autocomplete – Country Example - Phppot
jQuery Autocomplete function is called on the key-up event of the input field. This function requests PHP for the list of countries via...
Read more >jQuery autocomplete with callback ajax json - Stack Overflow
I'm trying to find a way to use jQuery autocomplete with callback source getting data via an ajax json object ...
Read more >Autocomplete - jQuery UI
Autocomplete. Enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering. Examples.
Read more >Make Autocomplete Search with jQuery AJAX - Makitweb -
Autocomplete search filter display suggestion based on the user input e.g. listing all products which start with the character 'a'.
Read more >Ajax Autocomplete for jQuery - GitHub
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields. It has no dependencies other than jQuery.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I came up with something that works pretty great. It requires
jquery.auto-complete.min.js
andjquery.auto-complete.css
from https://github.com/Pixabay/jQuery-autoComplete … which is beautifully coded, and only requires 3.4k.Let’s say you want an autocompleted city search input that shows the city name but returns the
city_id
…HTML:
(Note the
hidden
input. The code below modifies this value.)JS:
(The
renderItem
is nearly identical to the default, just modified thereturn
. If, like me, you will only ever do this kind of autocomplete, you can just replace that line in the source code, and omit therenderItem
from the call above. With a bit more work, this could be modified to not require#id
selectors in either JS or HTML.)PHP:
(Basically the PHP just outputs a JSON array like
[[255,'New York'], [1261,'New Orleans'], [8212,'Newark'], ...]
. Be sure to replacesafeGET()
with your own injection proofing methods.)So, get it here https://github.com/dellert/autocompleteajax