Let’s suppose we have a function for getting some data from database:
function getResults() {
if (httpReq.readyState == 4 || httpReq.readyState == 0) {
httpReq.open("GET",'../search.php?blablabla',true);
httpReq.onreadystatechange = function() {
if (httpReq.readyState == 4) {
// Some code here
}
};
httpReq.send(null);
}
updateResults();
// This function is running before the code above
// ...so I actually get no results
}
How to run the updateResults() function at the moment when results are already taken from database?
I think the code should be like this: