I have a group of select option and each are relational from top to bottom by ajax. This is works fine in insert mode. But in edit mode when i push data to perform ajax operation and set the selected value based on stored data, It sometime not setting the value though the data is loaded to DOM and sometime it's working.
Actually if any data would miss, all the next data won't be loaded. but here 3rd and 4th data missed but 5th data is loaded.
I can't figure it out what is the problem. Please help if possible.
This is one of the ajax function to load data to district section
function loadDistricts(division1, distidentifier) {
return $.ajax({
type: 'post',
url: 'GetDistricts',
data: {
get_option:division1
},
success: function(response) {
$(distidentifier).html(response);
}
});
}
This is the function to call the ajax function and select the proper value
function loadAdress(divi, diviselect, dist, distselect, upaz, upazselect, unio, unioselect, vill, villselect){ // Id of all address field and jquery selector pass here
$(diviselect).val(divi).trigger('change');
loadDistricts(divi, distselect).done(function() {
$(distselect).val(dist).prop('selected', 'selected').trigger('change');
loadUpazilla(dist, upazselect).done(function() {
$(upazselect).val(upaz).prop('selected', 'selected').trigger('change');
loadUnion(upaz, unioselect).done(function(){
$(unioselect).val(unio).prop('selected', true).trigger('change');
loadVillage(unio, villselect).done(function(){
$(villselect).val(vill).trigger('change');
});
});
});
});
}
And finally I called the function, with value and jqueryidentifire --
loadAdress(divipid, '#divisions', distpid, '#districts', upapid, '#upazila', unipid, '#allunions', villpid, '#villages');
Any suggestion is appreciated.