1

I know how to get the id of a video, but I want to check its validity too. If a video ID is good, there's the alert with "good ID", but when the url is wrong it fails. I've tried try-catch, fail, error, nothing worked. Is there any idea? :(

var video_id  = '29994384';
var video_url = 'http://vimeo.com/api/v2/video/' + video_id + '.json';

$.ajax({
    type: 'GET',
    url: video_url,
    data: {format: 'jsonp'},
    dataType: 'jsonp',
    crossDomain: true,
    success: function(resp) {
        alert('good ID');
    },
    error: function(resp) {
        alert('wrong ID');
    }
});
Charles
  • 50,943
  • 13
  • 104
  • 142
psylocke
  • 31
  • 1

1 Answers1

2

You can check other properties coming from response if they exists and if so, it is valid something like this:

success: function(resp) {
   if (resp['title']) {
      alert ('good ID');
   }
   else {
      alert ('bad ID');
   }
},
Sarfraz
  • 377,238
  • 77
  • 533
  • 578