/ Published in: JavaScript
A simple way to send an ajax request to the Bit.ly API and return the shortened url.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * author : Stephane P. Pericat * date : 2010-03-02 */ var link = "http://www.snipplr.com/"; var slink = null; var short = new Request.JSONP({ url: 'http://api.bit.ly/shorten', callbackKey: 'callback', onSuccess: function (result) { slink = result['results'][''+link+'']['shortUrl']; console.log(slink) }, data: { version: '2.0.1', longUrl: link, login: 'username', apiKey: 'R_dd761983d39ab216af226a19756496d3', format: 'json' } }).send();