JavaScript: Global variables after Ajax requests [duplicate]
问题 This question already has an answer here: How do I return the response from an asynchronous call? 36 answers the question is fairly simple and technical: var it_works = false; $.post("some_file.php", '', function(data) { it_works = true; }); alert(it_works); # false (yes, that 'alert' has to be here and not inside $.post itself) What I want to achieve is: alert(it_works); # true Is there a way to do that? If not can $.post() return a value to be applied to it_works ? 回答1: What you expect is