2011-12-13 27 views
3

我有郵件鏈接,比如在電子郵件正文中。現在的問題是我想單擊內容並能夠在正確的消息窗格(我使用jQuery)中顯示解包鏈接。如何確定網址縮短鏈接的最終鏈接,而無需在網頁中加載?

我正在使用jQuery,並認爲使用AJAX調用另一個PHP腳本發送請求bit.ly等將工作。我不是100%確定如何做到這一點。

主要問題是由於Twitter有自己的自動縮短功能,因此其中一些鏈接縮短了2-3倍。任何幫助,將不勝感激。

謝謝。

回答

3

您可以使用名爲LongURL的服務。在jQuery的API調用會是這個樣子:

$.ajax({ 
    url: 'http://api.longurl.org/v2/expand?format=json&url=http%3A%2F%2Fbit.ly%2Fv20RLs', 
    dataType: 'jsonp', 
    method: 'get', 
    success: function(response) { 
     alert(response['long-url']); 
    } 
}); 

$.ajax({ 
    url: 'http://api.longurl.org/v2/expand', 
    data: { 
     format: 'json', 
     url: 'http://bit.ly/v20RLs' 
    }, 
    dataType: 'jsonp', 
    method: 'get', 
    success: function(response) { 
     alert(response['long-url']); 
    } 
}); 
+0

哇不錯的建議,標記爲收藏;) –