如何使用 jQuery 生成 TinyURL
我正在尝试构建一个 jQuery 函数,该函数允许我出于微博原因(是的,twitter)从其他一些链接生成 TinyURL...我从 James Padolsey 找到了本教程,但没有从称呼。
http://james.padolsey.com/javascript/create-a- tinyurl-with-jsonp/
function requestShortURL(longURL, success) {
var API = 'http://reque.st/create.api.php?json&url=',
URL = API + encodeURIComponent(longURL) + '&callback=?';
console.log('tweet apit url: ' + URL);
$.getJSON(URL, function(data){
success && success(data.url);
});
}
requestShortURL('http://www.mycompany.com', function(shortened){
alert('new url: ' + shortened);
});
I'm trying to build a jQuery function that will allow me to produce a TinyURL from some other link for micro blogging reasons (yes, twitter)... I found this tutorial from James Padolsey, but am not getting a response back from the call.
http://james.padolsey.com/javascript/create-a-tinyurl-with-jsonp/
function requestShortURL(longURL, success) {
var API = 'http://reque.st/create.api.php?json&url=',
URL = API + encodeURIComponent(longURL) + '&callback=?';
console.log('tweet apit url: ' + URL);
$.getJSON(URL, function(data){
success && success(data.url);
});
}
requestShortURL('http://www.mycompany.com', function(shortened){
alert('new url: ' + shortened);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这似乎对我来说效果很好:
Hm that seems to work fine for me: