I have the population of 4 HTML select with Ajax, however I have a problem when returning the files, I tried to do asynchronously only that it was not good because the user can see each select being populated in order (besides the delay is ugly to see), when I changed my function to asynchronous and my Ajax too, I can not return data, example.
function GetDropdownList(table)
{
var DDItems;
function GetDropdownList_AjaxCallBack(data) {
DDItems = data;
};
$.ajax({
type: "POST",
url: "/Ajax/GetDropdownList",
dataType: "json",
data: {
table: table
},
async: true
})
.done(function (data) {
GetDropdownList_AjaxCallBack(data);
})
.fail(function (XMLHttpRequest, textStatus, errorThrown) {
console.log(errorThrown);
});
return DDItems;
}
async function PopulateDropDown(dropdownID) {
var dropdownItems = GetDropdownList(dropdownID);
console.log(dropdownItems.items);
}
PopulateDropDown("LicenseDocs_Midia");
PopulateDropDown("LicenseDocs_Regiao");
PopulateDropDown("LicenseDocs_Prazo");
PopulateDropDown("LicenseDocs_Use");
In console.log I get the following JS error:
TypeError: dropdownItems is undefined
I've found that to return asynchronous objects from Ajax just create a Callback, but it's not working and I can not find a solution ...