I'm taking a JavaScript course and I'm creating my own "challenge". Unfortunately, it takes the teachers days to respond, and I don't have that long. I tried searching for the answer, but I seem to have come up short.
I created a database and pumped the select * results out to a page to simulate an ajax call. I then wrote the following code:
const dataModule = (function() {
//fetch all data from ajax
return {
getData: function() {
const famData = fetch('http://localhost/Test2/ajaxservers/_test.php')
.then(result => {
return result.json()
});
}
}
})();
const uiModule = (function() {
//some code
})();
const controlModule = (function(data, ui) {
console.log(data.getData());
})(dataModule, uiModule)
as you can see, I'm using the Module pattern. I return a function in the dataModule to fetch the data. the function seems to work OK. if I add a line to it to do .then(data=> console.log(data));
I see the array returned, but if I call the function from the controlModule without console logging the fetch data, I get undefined. What am I missing?