I have simplified this a little to explain.
If I have multiple dependent selects lets take the simple country town region example.
First select loads countries and the second select load the towns relating to the country selected value and the third select loads the region relating to the town selected value.
I don't want to set async to false.
$(document).ready(function () {
// Enumerate select lists
// Country is already filled
enumerateChildDropDown("Town", $("Country").val());
// This shouldnt load until the above has finished
enumerateChildDropDown("region", $("Town").val());
// Note there could be many more of these
});
function enumerateChildDropDown(selectId, parentId) {
$.ajax({
type: "POST",
dataType: "json",
url: "@Url.Action("foo", "foo")",
data: { parentId: parentId},
}).done(function (returnedData) {
// Fill selectId here etc
}).fail(function (jqXHR, exception) {
// Some Alert
});
}
This example has been greatly simplified as the real app loads a lot of data to each select and has anything up to 10+ dependent fields hence the use of one ajax function.
I have looked at using some type of callback but I'm finding different examples of JQuery versions which makes things a little confusing. I want to stick to JQuery and not use any other library i.e. knockoutjs.