2011-12-13 29 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

哇不错的建议,标记为收藏;) –