Advertisement
Guest User

hglkjhfafafa

a guest
Nov 23rd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="en-US">
  3. <head>
  4. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  5. <script type="text/javascript">
  6. $(document).ready(function()
  7. {
  8.  
  9. $(".search_input").keyup(function()
  10. {
  11. var search_input = $(this).val();
  12. var keyword= encodeURIComponent(search_input);
  13. // Youtube API
  14. var yt_url='http://gdata.youtube.com/feeds/api/videos?q='+keyword+'&format=5&max-results=1&v=2&alt=jsonc';
  15.  
  16. $.ajax
  17. ({
  18. type: "GET",
  19. url: yt_url,
  20. dataType:"jsonp",
  21. success: function(response)
  22. {
  23.  
  24. if(response.data.items)
  25. {
  26. $.each(response.data.items, function(i,data)
  27. {
  28. var video_id=data.id;
  29. var video_title=data.title;
  30. var video_viewCount=data.viewCount;
  31. // IFRAME Embed for YouTube
  32. var video_frame="<iframe width='640' height='385' src='http://www.youtube.com/embed/"+video_id+"' frameborder='0' type='text/html'></iframe>";
  33.  
  34. var final="<div id='title'>"+video_title+"</div><div>"+video_frame+"</div><div id='count'>"+video_viewCount+" Views</div>";
  35.  
  36. $("#result").html(final); // Result
  37.  
  38. });
  39. }
  40. else
  41. {
  42. $("#result").html("<div id='no'>No Video</div>");
  43. }
  44. }
  45. });
  46. });
  47. var val = document.getElementById('search_input').value;
  48. fetch(val);
  49. });
  50. </script>
  51. // HTML code
  52. <input type="text" class='search_input' value="film" />
  53. <div id="result">
  54. </div>
  55. <body onload='ajax()'>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement