Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use jQuery to produce TinyURL

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);
});
like image 859
RSolberg Avatar asked Jul 10 '09 18:07

RSolberg


1 Answers

Hm that seems to work fine for me:

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');
like image 50
Daff Avatar answered Nov 08 '22 00:11

Daff