</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
<span class="question-originals-answer-count">
(38 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2015-03-14 04:25:21Z" class="relativetime">5 years ago</span>.</div>
</div>
</aside>
I've seen similar questions asked on SO but no quite my problem.
I have something like
var x = 5;
if( some condition ){
$.ajax({
url:"...",
success: function(response){
x = response.x;
}
}
}
some other logic
use x variable
What is happening is the thread executing the JS gets to the logic that uses x before the asynchronous task comes back.
Normally I would just put whatever logic inside the success function but I need the logic to happen regardless of whether or not the condition is met and I don't want to replicate code. Anyone have any suggestions? Should I just async to be false?
Thanks!
</div>