如何使用jQuery生成TinyURL

5
我正在尝试构建一个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);
});

请检查您的Javascript控制台(在Firefox中为工具>错误控制台),或使用Firebug的控制台 - 它可能会提供有用的错误消息。 - dbr
1个回答

8

嗯,对我来说似乎很好用:

function makeTinyUrl(url)
{
    $.getJSON('http://json-tinyurl.appspot.com/?url=' + url + '&callback=?', 
        function(data)
        { 
            alert(data.tinyurl); 
        }
    );
}

makeTinyUrl('https://dev59.com/-UjSa4cB1Zd3GeqPE184);

你认为可能是代理造成了这个问题吗?我已经复制了你提供的所有内容,但没有收到任何警告... - RSolberg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接