0

Trying to call methods of subject and that works splendid, I reach whatever info needed from the docs requested within the methods. Now I want to use that information outside of the methods and whenever I try that the variable come out undefined.

From what I have read these methods are asynchronous and hence the undefined result.

So, how to solve it? Doing a $.ajax({.. async:false..}) kind of works against the purpose, *a*jax is *a*sync. Any suggestions, except for the Q&D async:false option?

Pea-Pod
  • 79
  • 9
  • I guess you should ask yourself why do you need to call something synchronously in the browser. These methods take the callback parameter which will be called when the result is ready. – Marek Kowalski Sep 05 '13 at 11:31
  • @MarekKowalski. Yup, you are totally right. My understanding of the callback concept was rather shallow. Homework is done now and my own answer below edited accordingly. Thanks for _not_ giving an answer but rather have me ask the right questions - the foundation upon what all science rests. – Pea-Pod Sep 06 '13 at 21:24
  • @MarekKowalski. Forgot - write an answer and you've got my vote. Cheers! =) – Pea-Pod Sep 06 '13 at 21:41

1 Answers1

0

After some litt. studies and hack-arounds, this is my solution:

Use $.ajax({async:false}); and call it in a fork (web worker) to avoid the lockdown.

It aint pretty - but it works.

Still: are there any pretty solutions out there?

EDIT: There are prettier solutions out there and they are actually solutions instead of what I have written above. They are called 'callbacks' and I had not understood the concept fully until just now. If you don't want do my mistake please invest a few minutes here and save yourself some hours of agony.

Pea-Pod
  • 79
  • 9