I am developing a web application that requires querying my database multiple times. Each query depends on the data retrieved from the previous one, so I need to ensure each call completes before moving on to the next. I have attempted using async/await for this purpose, but it seems there may be an issue with my approach. Can someone provide guidance on the correct way to achieve this?
var firstCall = new XMLHttpRequest();
var firstCallData;
async function initiateFirstCall() {
firstCall.open('GET', queryURL);
firstCall.onload = function() {
firstCallData = JSON.parse(firstCall.responseText);
};
firstCall.send();
};
async function displayData() {
await initiateFirstCall();
console.log(firstCallData);
}
displayData();
I have some experience in JavaScript, although I do not frequently write code in it and might not fully understand how async/await functions work. Any assistance or insights would be greatly appreciated!