Chris Domigan wrote: > > Having your scripts broken down into several functions isn't at all an > ugly > way to do things. IMHO everything should be in a function except for > globals. Makes program control a lot easier :) >
See following 3 different ways to do the same thing. When referring to "silliness" I was referring to the second one, with all its callbacks and such. Last one looks quite nice and compact, but as createSeed-function would be called from more than one function it would make sense to keep it as seperate function. In first one, it is function of its own (notice 'false' as last parameter for $.post, meaning asyncronous = false), even when usage of global variables for this kind of purpose probably isn't encouraged. However, I think I'll use the last one, as createSeed isn't very large function. --------------------------------------------------------------------- var seed_id; var seed; function createSeed() { $.post('login/login.php', {action:'createseed'}, function(data) { results = data.split('|'); var seed_id = results[0]; var seed = results[1]; }, false); } function validateLogin() { createSeed(); [..send seed_id, hashstring and login information to server for check..] } --------------------------------------------------------------------- function createSeed(callback) { $.post('login/login.php', {action:'createseed'}, function(data) { results = data.split('|'); callback.call(); }); } function validateLogin() { createSeed(function() { var seed_id = results[0]; var seed = results[1]; [..send seed_id, hashstring and login information to server for check..] }); } --------------------------------------------------------------------- function validateLogin() { $.post('login/login.php', {action:'createseed'}, function(data) { results = data.split('|'); var seed_id = results[0]; var seed = results[1]; [..send seed_id, hashstring and login information to server for check..] }); } -- View this message in context: http://www.nabble.com/Setting-a-global-variable-tf2764461.html#a7723506 Sent from the JQuery mailing list archive at Nabble.com. _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/