$('#country_id').on('change', function(e) { e.preventDefault(); var country_id = $(this).val(); var body = ""; $.ajax({ type: 'POST', url: provincesByCountryId, data: { _token: $("meta[name='csrf-token']").attr('content'), country_id: country_id, }, success: function(response) { // if(typeof(response) != "object"){ // response = JSON.parse(response); // } $('#province_id').html(''); $('#district_id').html(''); body = ''; if (response.states) { $.each(response.states, function(key, state) { body += ""; }); $('#province_id').html(body); } } }) }) $('#province_id').on('change', function(e) { e.preventDefault(); var state_id = $(this).val(); var body = ""; $.ajax({ type: 'POST', url: districtByProvinceId, data: { _token: $("meta[name='csrf-token']").attr('content'), state_id: state_id, }, success: function(response) { $('#district_id').html(''); body = ''; if (response.districts) { console.log(response.districts); $.each(response.districts, function(key, district) { body += ""; }); $('#district_id').html(body); } } }) })