> I'd ideally just like the function to return the shortUrl from the > json results but can't seem to get it anywhere but the callback > function.
... > $.getJSON("http://api.bit.ly/shorten?version=2.0.1&longUrl=" > + url + "&login=" + apiLogin + "&apiKey=" + apiKey, function(data){ > shortURL = data.results[url].shortUrl; > }); > return shortURL; You're returning shortURL from the function before $.getJSON has returned! The shortenURL function can't run synchronously and return the URL if it's calling an asynchronous ajax method. Instead of returning the URL, the function should pass in a callback.