The first "a" ajax means asynchrony, and so what you are trying to do is similar to the ajax philosophy. However, you can use a lock request, but this is not supported by the simplified .get interface, and you should use the .ajax function:
var foo = "hmmm"; $.ajax("jquery.js", {async:false, success:function(x){foo=x}}); alert(foo);
The main javascript execution model is event-based and single-threaded (there are web workers who provide multi-threading capabilities, but each employee lives in their own address space and cannot share any memory with other employees or the main thread. Therefore, in a sense, they more like processes than threads).
In Javascript, you cannot βwaitβ in a loop for other events, you should always stop working quickly, perhaps by attaching callbacks that will be called again when something happens. If you make a loop, the javascript engine will just get stuck in that loop and will not be able to do other processing (if it is visible from javascript). For instance:
Will NOT work because the browser engine is not allowed to execute other javascript code (timeout callback) until the main code path completes.
This event-based approach simplifies programming (because there is no need for blocking ... there is always only one state-controlling thread), but it forces you to use a different thread project for lengthy operations.
The fact that there is one thread of execution also means that although your javascript code does any lengthy calculations, everything else is blocked and the browser looks immune to the user.
This irresponsibility is why using synchronous calls to retrieve resources is considered bad practice ... the difficult task of acquiring different resources from multiple threads at the same time is already implemented by the browser, but your javascript code is needed to use the callback to be able to use this feature.