Hey all,
I am attempting to turn this "one shot" script into something more extensible. The problem is that I cannot figure out how to get the callback function to set a value outside of itself (please note that references to the Bit.ly API and the prototype.js frame work which are required have been left out due to login and apiKey information):
CURRENTLY WORKING CODE
var setShortUrl = function(data) {
var resultOBJ, myURL;
for(x in data.results){resultOBJ = data.results[x];}
for(key in resultOBJ){if(key == "shortUrl"){myURL = resultOBJ[key];}}
alert(myURL);
} BitlyClient.shorten('http://www.thinkgeek.com', 'setShortUrl');
PROPOSED CHANGES
var setShortUrl = function(data) {
var resultOBJ, myURL;
for(x in data.results){resultOBJ = data.results[x];}
for(key in resultOBJ){if(key == "shortUrl"){myURL = resultOBJ[key];}}
alert(myURL);
return myURL;
} var myTEST = BitlyClient.shorten('http://www.thinkgeek.com', 'setShortUrl'); alert(myTEST);
As you can see this doesn't work the way I'm am expecting. If I could get a pointer in the right direction it would be most appreciated.
Thanks,
- MT