jQuery的Vimeo ID有效性 [英] Vimeo ID validity with jQuery
本文介绍了jQuery的Vimeo ID有效性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何获取视频ID,但是我也想检查其有效性.如果视频ID正确,则会出现带有良好ID"的警报,但是如果网址错误,则会失败.我尝试了try-catch,失败,错误,没有任何效果. 有什么主意吗:(
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');
}
});
推荐答案
您可以检查其他属性来自响应(如果存在),并且有效,例如:
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');
}
},
这篇关于jQuery的Vimeo ID有效性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文