Вот документация по автозаполнению пользовательского интерфейса jQuery:
http://jqueryui.com/autocomplete/
Вот пример того, как это следует реализовать:
var AutoCompleteOptions = { source: function( request, response ) {
$.ajax({
url: 'your URL here',
dataType: "json",
data: {
itemToSearch: request.term // could be any data you are passing in for search
},
success: function(data) {
// do something where search values are returned
},
});
},
select: $.proxy(function(event, ui){
// what you want to do with that information
// using a proxy to preserve the reference to 'this'
return false; // prevent the default response (typically inserting the selected value into the textbox the dropdown is being displayed from.
},this),
open: function(event, ui) {
// things to do when the dropdown is rendered
return false; // prevent default autocomplete open action
},
focus: function(event, ui) {
// what to do when an the user hovers over an item in the drop down
return false; // prevent default autocomplete open action
},
minLength:0 // be sure to set this if you want to be able to trigger the search event manually and have it display results
};
var Input = $("input");
Input.autocomplete(this.AutoCompleteOptions)