Re: [jQuery] Setting a global variable

2006-12-07 Thread kazaar
Chris Domigan wrote: > > Synchronous ajax calls freeze the entire *browser* until completed, not > just > the current script, whereas asynchronous calls do not. Google "ajax > synchronous" for better info on why this is not desirable behaviour. > It could be, that I've been using "too much" Fi

Re: [jQuery] Setting a global variable

2006-12-06 Thread Chris Domigan
Here's a great blog post from Doug Crockford, one of the gods of Javascript on the subject: Many people prefer to use it synchronously. When used this way, the JavaScript engine is blocked until the interaction with the server is complete. Because it blocks, the flow of control looks a lot l

Re: [jQuery] Setting a global variable

2006-12-06 Thread Chris Domigan
On 07/12/06, kazaar <[EMAIL PROTECTED]> wrote: I'm aware of this, but there can be situations where script can not be allowed to continue, before certain "stuff" has been done for sure. Synchronous ajax calls freeze the entire *browser* until completed, not just the current script, whereas a

Re: [jQuery] Setting a global variable

2006-12-06 Thread kazaar
I'm aware of this, but there can be situations where script can not be allowed to continue, before certain "stuff" has been done for sure. Klaus Hartl-3 wrote: > > Synchronous loading isn't the wisest thing to > choose. If for instance the request needs a long time due to network > problems o

Re: [jQuery] Setting a global variable

2006-12-06 Thread kazaar
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 t

Re: [jQuery] Setting a global variable

2006-12-05 Thread Klaus Hartl
Chris Domigan schrieb: > 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 :) And in addition to this: Synchronous loading isn't the wisest thing to cho

Re: [jQuery] Setting a global variable

2006-12-05 Thread Chris Domigan
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 :) ___ jQuery mailing list discuss@jquery.com http://jquery.com/d

Re: [jQuery] Setting a global variable

2006-12-05 Thread kazaar
Ok, I'm choosing that path while waiting for jQuery 1.1. Works fine. It's not so critical issue, but the resulting code looks.. well, silly. Chris Domigan wrote: > > Synchronous loading is proposed for jQuery 1.1. But I'm sure callbacks > would > be able to do what you need... > > Couldn't you

Re: [jQuery] Setting a global variable

2006-12-05 Thread Chris Domigan
Synchronous loading is proposed for jQuery 1.1. But I'm sure callbacks would be able to do what you need... Couldn't you just do: createSeed(restOfScript); function restOfScript() { ... } Then the rest of the script would run after the ajax request has returned. Chris On 06/12/06, kazaar <[E

Re: [jQuery] Setting a global variable

2006-12-05 Thread kazaar
Thank you for quick answers. However, problem still exists. Latter alert-function would still fail, because variables wouldn't be set yet at that moment (I will need those variables later in another call to server). Problem falls back to asyncronous loading. Isn't there an easy way to use syncrono

Re: [jQuery] Setting a global variable

2006-12-05 Thread Chris Domigan
Like Blair says, you need to use a callback. I'd do something like this: var seed_id; var seed; function createSeed(callback) { $.post('login/login.php',{action:'createseed'}, function(data) { results = data.split('|'); seed_id = results[0]; seed = results[1]; if (callback) c

Re: [jQuery] Setting a global variable

2006-12-05 Thread Blair McKenzie
You would need to put the alerts inside the post callback as well. The request response is probably coming back AFTER all of the JS has been processed on page load. Blair On 12/5/06, kazaar <[EMAIL PROTECTED]> wrote: How should I change the following, so those 2 global variables would be fill

[jQuery] Setting a global variable

2006-12-05 Thread kazaar
How should I change the following, so those 2 global variables would be filled with information returned by server? Code below doesn't do it. Could this have something to do with asyncronous loading or something? var seed_id; var seed; function createSeed() { $.post('login/login.php',{acti