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!

Kofi Sarfo modified theme by Mads Kristensen



Content by WIMIRO Technology is licensed under a Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License.

Creative Commons License

Powered by BlogEngine.NET 1.5.0.7

About Me

Director, Wimiro Technology
London, United Kingdom

Writes in third person and first person plural; currently commutes to Moorgate.

Kiva Loans

  • Norma

    Norma

    Farming

    Requested loan: $900

    Amount raised: $0

    Tarma, Peru

    Fertilizer

    Loan Now »

  • Buyanbaatar Munkhbayar

    Buyanbaatar Munkhbayar

    Taxi

    Requested loan: $2675

    Amount raised: $0

    Darkhan, Mongolia

    To build a warm garage for his car and buy wool threads for his wife's business

    Loan Now »

  • Bayarmaa Bayaraa

    Bayarmaa Bayaraa

    Retail

    Requested loan: $400

    Amount raised: $0

    Hentiy,, Mongolia

    To purchase more supplies

    Loan Now »

 To see more entrepreneurs »

Kiva Loans