Skip to content

Instantly share code, notes, and snippets.

@dovidezra
Created June 1, 2017 02:48
Show Gist options
  • Save dovidezra/06e716b7af65bd14368ad92c32bf313b to your computer and use it in GitHub Desktop.
Save dovidezra/06e716b7af65bd14368ad92c32bf313b to your computer and use it in GitHub Desktop.
CDN hosted jQuery based Autocomplete script with Millions of Suggestions. Details: https://knowledgebasehub.com
var KnowledgebaseHub;
$(document).ready(function () {
$("#search").autocomplete({
source: function(request, response) {
$.getJSON("https://suggestqueries.google.com/complete/search?callback=?",
{
"hl":"en", // "en" is english. see documentation for more languages
"ds":"", // Force youtube suggestions, use "yt"
"jsonp":"KnowledgebaseHub", // jsonp callback function name
"q":request.term, // search term
"client":"youtube" // force jsonp response
}
);
KnowledgebaseHub = function (data) {
var suggestions = [];
$.each(data[1], function(key, val) {
suggestions.push({"value":val[0]});
});
suggestions.length = 5; // show upto 10 suggestions
response(suggestions);
};
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment