“JQuery Dropdown -Optionen in Laravel” Code-Antworten

JQuery Dropdown -Optionen in 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

JQuery Dropdown -Optionen in 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

Ähnliche Antworten wie “JQuery Dropdown -Optionen in Laravel”

Fragen ähnlich wie “JQuery Dropdown -Optionen in Laravel”

Weitere verwandte Antworten zu “JQuery Dropdown -Optionen in Laravel” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen