2014-03-02 46 views
0

Im顯示存儲在數據庫中的隨機嵌入鏈接。這些嵌入鏈接到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> 

或者的SoundCloud嵌入:

<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

我認爲這是可能的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"); 
}) 
+0

但那就意味着,我需要非常改變網址...難道我得到它的權利? –

+0

對不起,但不能檢查iframe狀態碼是否跨域。如果你想處理錯誤,你必須使用API​​,http://developers.soundcloud.com/docs/api/sdks#javascript – ocanal