İl İlçe Jquery Ajax İsteği
12-07-2020İl ilçe bilgilerinin çekilmesi işlemi
HTML Tasarım Kısmı
<div class="row"> <div class="col-sm-6 form-group"> <label>Şehir * :</label> <select id="txtSehir" name="txtSehir" class="form-control select2 git ililce" required=""> <option value="">Seçiniz</option> @foreach($cities as $city) <option value="{{$city->id}}">{{$city->name}}</option> @endforeach </select> </div> <div class="col-sm-6 form-group"> <label>İlçe * :</label> <select id="txtIlce" name="txtIlce" class="form-control select2 ililce" required=""> <option value="">Seçiniz</option> </select> </div> </div>
Ajax İstek
$(document).ready(function () { $('#txtSehir').on('change', function () { $.getJSON('{{route('api.pool.districts')}}', {'city-id': this.value}) .done(function (json) { $('#txtIlce').html(''); $.each(json.data, function (i, item) { $('#txtIlce').append($('<option>', { value: item.id, text: item.name })); }); }).fail(function (jqxhr, textStatus, error) { var err = textStatus + ", " + error; console.log("Request Failed: " + jqxhr.responseJSON.message); }); }