如何使用jQuery产生TinyURL [英] How to use jQuery to produce TinyURL

查看:108
本文介绍了如何使用jQuery产生TinyURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个jQuery函数,该函数将允许我出于微博客的原因(是,twitter)从其他链接生成TinyURL ...我从James Padolsey找到了本教程,但没有得到回应从电话回来.

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);
});

推荐答案

嗯,对我来说似乎很好:

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');

这篇关于如何使用jQuery产生TinyURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆