javascript - Youtube Search js function -
while searching @ stackoverflow, found code below :
$(document).ready(function () { $("#show").click(function () { getyoutube($("#search").val()); }); });
function getyoutube(title) { $.ajax({ type: "get", url: yt_url = 'http://gdata.youtube.com/feeds/api/videos?q=' + title + '&format=5&max-results=1&v=2&alt=jsonc', datatype: "jsonp", success: function (response) { if (response.data.items) { $.each(response.data.items, function (i, data) { var video_id = data.id; var video_title = data.title; var video_viewcount = data.viewcount; $("#result").html(video_id); }); } else { $("#result").html('false'); } } }); }
how can edit code keep function? want able use : getyoutube(my_keywords);
also, how can save function output variable? : var_name = getyoutube(my_keywords); ok?
thnx! ;)
yes, can use without $(document).ready. no, function not return anything
to "return" value ajax:
$.ajax({ ... success: function(datafromserver) { processserveroutput(datafromserver); } }); function processserveroutput(somestring) { alert(somestring); }
Comments
Post a Comment