假设我们有一个从数据库获取一些数据的函数:
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
}
如何updateResults()
在已经从数据库中获取结果的那一刻运行该函数?