我想建立一个jQuery的功能,让我从其他一些链接,微博的原因产生TinyURL的(是的,微博)......我发现从詹姆斯Padolsey本教程,但我没有得到回应从回呼。

http://james.padolsey.com/javascript/create -a-TinyURL的与 - 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);
});
有帮助吗?

解决方案

这似乎很好地工作

嗯对我来说:

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');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top