But in the ajax request you can set async to false (a few lines down) and that seemed to fix my issue by causing it to block until the data was received and the function completed.