Vimeo ID validity with jQuery

对着背影说爱祢 提交于 2019-12-08 03:58:29

问题


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');
    }
});

回答1:


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');
   }
},


来源:https://stackoverflow.com/questions/7873509/vimeo-id-validity-with-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!