문제

나는 마이크로 블로깅 이유 (예, 트위터)에 대한 다른 링크에서 작은 링크를 생성 할 수있는 jQuery 함수를 구축하려고 노력하고 있습니다 ... 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);
});
도움이 되었습니까?

해결책

나에게 잘 작동하는 HM :

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