Thank you, John Resig!

by Kofi Sarfo 17. June 2009 04:56

So we had the option of writing some code in order to determine browser responsiveness to see whether the code in the last post - AJAX and the URL short(ening) - was in fact asynchronous... or use jQuery which we know is most definitely AJAX. Really, we're not in the mood for poking under the hood.

There was a wee bit of pain in the why now isn't ths working stakes, some edits later and it did. Mysteriously. So I didn't touch it anymore. A case of Programming by Coincidence?


<script src="Scripts/jquery-1.2.6.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var getBitlyUrl = function() {

// set up default options
var defaults = {
version: '2.0.1',
login: 'bitlyapidemo',
apiKey: 'R_0da49e0a9118ff35f52f629d2d71bf07',
history: '1',
longUrl: $('#rawUrl').val()
};

// Build the URL to query
var daurl = "http://api.bit.ly/shorten?"
+ "version=" + defaults.version
+ "&longUrl=" + defaults.longUrl
+ "&login=" + defaults.login
+ "&apiKey=" + defaults.apiKey
+ "&history=" + defaults.history
+ "&format=json&callback=?";

$.getJSON(daurl, function(data) {
$('#bladder').empty();
$('#bitlyUrl').val(data.results[defaults.longUrl].shortUrl);
});
}

$('#getUrl').bind('click', getBitlyUrl);
})
(jQuery);
</script>

The body is the same as in the previous post. It's that easy. Great library.

Notes:
One of the leetlest problems we had was with receiving a 'permission denied' error when omitting "&format=json&callback=?" from the default URL. Solution and Nabble discovery all at the same time!

Comments are closed

Kiva Loans

  • 04-06-03-Nam Ngạn Group

    04-06-03-Nam Ngạn Group

    Fruits & Vegetables

    Requested loan: $2300

    Amount raised: $0

    Thanh Hoa City, Viet Nam

    to purchase vegetables to resell.

    Loan Now »

  • Maa Maheswari-1 Group

    Maa Maheswari-1 Group

    Food Production/Sales

    Requested loan: $1275

    Amount raised: $0

    Bhawanipatna,Kalahandi,Odisha, India

    to pay for purchasing ready-made pickles, mangos, oil, spices, etc.

    Loan Now »

  • 04-11-06-Nam Ngạn Group

    04-11-06-Nam Ngạn Group

    Fish Selling

    Requested loan: $2000

    Amount raised: $0

    Thanh Hoa City, Viet Nam

    to purchase fish to resell.

    Loan Now »

To see more entrepreneurs »

Make a loan to an entrepreneur across the globe for as little as $25. Kiva is the world's first online lending platform connecting online lenders to entrepreneurs across the globe.