I am doing validation for my Youtube
url text field.
I need to check, if the Youtube
url does not exist I should throw error, I followed this answer and created the jsfiddle to check it.
It works for valid url but it does not work for invalid url. All I see is 404 error in network console
Is there a way to check if url exist in client side using JavaScript
and jQuery
.
here is my code :
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);
}
});