AJAX race conditions
This looks so stupidly simple, but I can't figure it out and it's really holding me up.
Using XMLHttpRequest I can make a function to process the contents of another file, but I can't find a way to make a function to return the contents of another file.
For example,
( this worksCollapse )
whereas
( this wontCollapse )
It's obviously a race condition - as XMLHttpRequest runs as a seperate thread the getFile() function is exiting before the inner function has completed and will always return "no data".
Problem is, I can't think of a way to work around it. Can anyone help me out? I'm sure this must be a reasonably common problem.