Skip to content

Instantly share code, notes, and snippets.

@chandsie
Created January 3, 2013 05:17
Show Gist options
  • Save chandsie/4441018 to your computer and use it in GitHub Desktop.
Save chandsie/4441018 to your computer and use it in GitHub Desktop.
YouTube Search Autocomplete Example
var suggestCallBack; // global var for autocomplete jsonp
$(document).ready(function () {
$("#search").autocomplete({
source: function(request, response) {
$.getJSON("http://suggestqueries.google.com/complete/search?callback=?",
{
"hl":"en", // Language
"ds":"yt", // Restrict lookup to youtube
"jsonp":"suggestCallBack", // jsonp callback function name
"q":request.term, // query term
"client":"youtube" // force youtube style response, i.e. jsonp
}
);
suggestCallBack = function (data) {
var suggestions = [];
$.each(data[1], function(key, val) {
suggestions.push({"value":val[0]});
});
suggestions.length = 5; // prune suggestions list to only 5 items
response(suggestions);
};
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment