Skip to content

Instantly share code, notes, and snippets.

@agounaris
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agounaris/33ea80eb8695701026e9 to your computer and use it in GitHub Desktop.
Save agounaris/33ea80eb8695701026e9 to your computer and use it in GitHub Desktop.
an ajax request to populate suggestions on a search field, elasticsearch content
$(function() {
var ajaxLoading = false;
$( "#search" ).keypress(function() {
var postData = {
"suggest" : {
"text" : $("#search").val(),
"completion" : {
"field" : "suggest"
}
}
};
if(!ajaxLoading) {
ajaxLoading = true;
$("#search").autocomplete({
source: function(request, response){
$.ajax({
url: "/search/suggest",
type: "GET",
dataType: "JSON",
data: JSON.stringify(postData),
success: function (data) {
response(data);
ajaxLoading = false;
}
});
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment