<script type="text/javascript">
$(function() {
var cache = {};
var last_xhr;
$("#search_input").autocomplete({
minLength: 3,
source: function (request, response) {
var term = request.term;
if ( term in cache ) {
response(cache[term]);
return;
}
last_xhr = $.getJSON("/server-side/search.php", request, function(data, status, xhr) {
cache[term] = data;
if ( xhr === last_xhr ) {
response(data);
}
});
}
}).autocomplete("widget").addClass('ui-search-results');
$('#search_input').data("autocomplete")._renderItem = function(ul, item) {
return createElement(item)
.data("item.autocomplete", item)
.appendTo(ul);
};
});
</script>
No comments:
Post a Comment