“Opsi dropdown jQuery di Laravel” Kode Jawaban

Opsi dropdown jQuery di Laravel

@section('scripts')
    <script type="text/javascript">
        $("#country").change(function(){
            $.ajax({
                url: "{{ route('admin.cities.get_by_country') }}?country_id=" + $(this).val(),
                method: 'GET',
                success: function(data) {
                    $('#city').html(data.html);
                }
            });
        });
    </script>
@endsection
Homely Hamster

Opsi dropdown jQuery di Laravel

public function get_by_country(Request $request)
{
    abort_unless(\Gate::allows('city_access'), 401);

    if (!$request->country_id) {
        $html = '<option value="">'.trans('global.pleaseSelect').'</option>';
    } else {
        $html = '';
        $cities = City::where('country_id', $request->country_id)->get();
        foreach ($cities as $city) {
            $html .= '<option value="'.$city->id.'">'.$city->name.'</option>';
        }
    }

    return response()->json(['html' => $html]);
}
Homely Hamster

Jawaban yang mirip dengan “Opsi dropdown jQuery di Laravel”

Pertanyaan yang mirip dengan “Opsi dropdown jQuery di Laravel”

Lebih banyak jawaban terkait untuk “Opsi dropdown jQuery di Laravel” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya