$('#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.provinces) { $.each(response.provinces, function(key, province) { body += ""; }); $('#province_id').html(body); } } }) }) $('#province_id').on('change', function(e) { e.preventDefault(); var province_id = $(this).val(); var body = ""; $.ajax({ type: 'POST', url: districtByProvinceId, data: { _token: $("meta[name='csrf-token']").attr('content'), province_id: province_id, }, success: function(response) { $('#district_id').html(''); body = ''; if (response.districts) { $.each(response.districts, function(key, district) { body += ""; }); $('#district_id').html(body); } } }) })