我有消息链接,比如在电子邮件正文中。现在的问题是我想单击内容并能够在右侧消息 Pane 中显示展开的链接(我使用 jQuery)。
我正在使用 jQuery 并认为使用 AJAX 调用另一个 PHP 脚本以将请求发送到 bit.ly 等是可行的。我不是 100% 确定如何执行此操作。
主要问题是其中一些链接被缩短了 2-3 倍,因为 Twitter 有自己的自动缩短器。如有任何帮助,我们将不胜感激。
谢谢。
最佳答案
您可以使用名为 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']);
}
});
关于javascript - 如何在不加载页面内的情况下确定 url 缩短链接的最终链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8488378/