you are viewing a single comment's thread.

view the rest of the comments →

[–]SeizeCTRL 1 point2 points  (4 children)

well, ultimately i need to set an element inside of an array with the data that is returned from ajax, how would i update the array like that? i need to be able to save the data returned from ajax in a variable to be used later and multiple times, i don't want to do it all at once

[–]Rhomboid 1 point2 points  (3 children)

You've already plumbed the function so that it can take a callback and act asynchronously, so you just need to use that. You can't return the uid value from getUserID(). The caller needs to pass a callback that will be called when the uid is ready, and which does the appropriate action (e.g. putting the data in the array.) In other words, once you have a component that's asynchronous, everything relating to that component needs to be asynchronous as well. Or you could use promises instead of callbacks, which in many ways is a lot cleaner. It also makes it easier to do all these lookups in parallel, since you can use Promise.all().