如何检查嵌入链接的有效性

时间:2014-03-02 13:42:55

标签: javascript php embed soundcloud

我显示存储在数据库中的随机嵌入链接。这些嵌入链接到mixcloud.com和soundcloud.com服务器上的一些音乐。但是用户可以删除他们的音乐,因此其中一些嵌入可能会失效。例如,我在我的数据库中嵌入了这个mixcloud:

<iframe frameborder="0" height="200" 
src="//www.mixcloud.com/widget/iframe/?feed=http%3A%2F%2Fwww.mixcloud.com%2Fmeik-sebastien-muller%2Fclickclack%2F&amp;
embed_uuid=3064105d-9dbc-4907-b999-8c7076a19ca8&amp;
stylecolor=&amp;
embed_type=widget_standard&amp;
hide_cover=" 
width="480">
</iframe>

or soundcloud embed:

<iframe frameborder="no" height="166" scrolling="no"     
src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F86361501&amp;
show_artwork=true" 
width="100%">
</iframe>

有没有办法检查服务器上的音乐是否仍然存在,所以如果音乐已被删除,我可以从数据库中选择另一个嵌入?

1 个答案:

答案 0 :(得分:1)

我认为使用api是可能的,

$.getJSON("https://api.soundcloud.com/tracks/86361501?client_id=0f8fdbbaa21a9bd18210986a7dc2d72c&format=json").error(function() {
   alert("ups, there is an error, that track is not available");
})