I have a problem how to properly call/return one function data. I have this function displayTableWithCountryStates which is calling getCountryStates function. The problem is that when i make request $.get i get proper response, but when i try to return this response, console.log(countryStates) inside displayTableWithCountryStates is empty
countryStatesTables = {
displayTableWithCountryStates: function (source, newForm) {
var countryId = 237;
var countryStates = countryStatesTables.getCountryStates(countryId);
console.log(countryStates); // Response is empty
},
getCountryStates: function (countryId) {
if (countryId !== '' || countryId !== 'undefined') {
$.get(balthazar.settings.logistics.getCountryStatesUrl.url + '/' + countryId, function (data) {
console.log(data.data); //Response is ok, data is present
return data.data;
});
}
}
};
Why and how to properly return data in my displayTableWithCountryStates function. If you need any additional informations, please let me know and i will provide. Thank you!