5

マイクロブログの理由で他のリンクからTinyURLを生成できるようにするjQuery関数を構築しようとしています(はい、Twitter)... 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);
});
4

1 に答える 1

8

うーん、私にとってはうまくいくようです:

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

makeTinyUrl('http://stackoverflow.com/questions/1111171/how-to-use-jquery-to-produce-tinyurl');
于 2009-07-10T18:50:19.220 に答える