@hitesh, remove the data type: "jsonp" from the ajax request. This way you will get json string if video id is available and if it is not available, ajax error callback will be called. I tried your violin and its work. Try it like this -
//var videoID = 'kn8yzJITdvI';//not working var videoID = 'p4kIwWHP8Vc';//working $.ajax({ url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json", //dataType: "jsonp", success: function(data) { console.log(data) $("#result").text(data); }, error: function(jqXHR, textStatus, errorThrown) { // Handle errors here alert('ERRORS: ' + textStatus); } });
Here is another short implementation for the solution you need -
//var videoID = 'kn8yzJITdvI';//not working var videoID = 'p4kIwWHP8Vc';//working $.getJSON('http://gdata.youtube.com/feeds/api/videos/'+videoID+'?v=2&alt=jsonc',function(data,status,xhr){ alert(data.data.title); }).error(function() { alert("error"); });
source share