[Solved] How to wait until the ajax command finished in JavaScript?


You has called xmlhttp.open(“GET”, “yearselectionchanged.php?q=” + value, true);

But the last param would be false, like this:

xmlhttp.open(“GET”, “yearselectionchanged.php?q=” + value, false);

True is a async request, then your code does not wait for response. And False is sync, your code will wait for response.

See the documentation here: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests#Synchronous_request

4

solved How to wait until the ajax command finished in JavaScript?