Skip to content

Instantly share code, notes, and snippets.

@jpablobr
Created March 15, 2011 15:22
Show Gist options
  • Save jpablobr/870872 to your computer and use it in GitHub Desktop.
Save jpablobr/870872 to your computer and use it in GitHub Desktop.
jQuery(function () {
var cache = {},
url = "/posts/autocomplete",
lastXhr;
jQuery("#SearchFormInputId").autocomplete({
minLength: 2,
delay: 125,
html: true,
source: function(request, response) {
var term = request.term;
if (term in cache) {
response(cache[term]);
return;
}
lastXhr = jQuery.getJSON(url, request, function(data, status, xhr) {
cache[ term ] = data;
if (xhr === lastXhr) {
response(data);
}
});
},
select: function (event, ui) {
jQuery("#SearchForm").submit();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment