OnChange (Division->District) [jQuery and AJAX]
$("#division").change(function () {
var divisionId = $('#division').val();
$(this).after('<span class="loading_data">Loading...</span>');
var self = $(this);
$.ajax({
type: "GET",
url: "<?php echo url(); ?>/users/get-district-by-division",
data: {
divisionId: divisionId
},
success: function (response) {
var option = '<option value="">Select One</option>';
if (response.responseCode == 1) {
$.each(response.data, function (id, value) {
option += '<option value="' + id + '">' + value + '</option>';
});
}
$("#district").html(option);
$(self).next().hide();
}
});
});
public function getDistrictByDivision(Request $request) {
$division_id = $request->get('divisionId');
$districts = AreaInfo::where('PARE_ID', $division_id)
->orderBy('AREA_NM', 'ASC')
->lists('AREA_NM', 'AREA_ID');
$data = ['responseCode' => 1, 'data' => $districts];
return response()->json($data);
}
var divisionId = $('#division').val();
$(this).after('<span class="loading_data">Loading...</span>');
var self = $(this);
$.ajax({
type: "GET",
url: "<?php echo url(); ?>/users/get-district-by-division",
data: {
divisionId: divisionId
},
success: function (response) {
var option = '<option value="">Select One</option>';
if (response.responseCode == 1) {
$.each(response.data, function (id, value) {
option += '<option value="' + id + '">' + value + '</option>';
});
}
$("#district").html(option);
$(self).next().hide();
}
});
});
public function getDistrictByDivision(Request $request) {
$division_id = $request->get('divisionId');
$districts = AreaInfo::where('PARE_ID', $division_id)
->orderBy('AREA_NM', 'ASC')
->lists('AREA_NM', 'AREA_ID');
$data = ['responseCode' => 1, 'data' => $districts];
return response()->json($data);
}
Comments
Post a Comment