In this code snippet, I am using the video ID 'TOwd30wXc-0' from YouTube:
$.ajax({
url: "http://gdata.youtube.com/feeds/api/videos/"+realurl+"?v=2&alt=json-in-script",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function (data) { PreviewVideo(data) }
});
The function PreviewVideo(data) is responsible for parsing the JSON response and performing other operations.
One issue I encountered is that when an incorrect video ID is provided, there is no indication of it. I tried adding
error: function() { alert('error occurred') }
to $.ajax but it did not work as expected.
Is there a method to determine whether the video ID is valid or not? Ideally, if the video exists, call PreviewVideo(data), otherwise call VideoError().
EDIT: When I input an invalid ID, I receive the following message in the JavaScript console (Chrome):
GET http://gdata.youtube.com/feeds/api/videos/TOwd30wXc-?v=2&alt=json-in-script&callback=jQuery17205096300751902163_1353530502856&_=1353530692237 400 (Bad Request)
Your insights and solutions are appreciated.